public void Execute(int index) { int currentState = States[index].State; float cd = States[index].CoolDown - DeltaTime; if (cd < 0) { PedestrianState newstate = States[index]; PedestrianData newdata = PedestrianData[index]; InstanceRendererProperty newproperty = StateProperty[index]; int nextstate = NextState(currentState); newproperty.Value = PedestrianAnimStateConfig.StateFrameRange[nextstate]; newstate.CoolDown = RdGen.NextFloat( PedestrianAnimStateConfig.DurationRange[nextstate].x, PedestrianAnimStateConfig.DurationRange[nextstate].y); newdata.Speed = RdGen.NextFloat( PedestrianAnimStateConfig.SpeedRange[nextstate].x, PedestrianAnimStateConfig.SpeedRange[nextstate].y); StateProperty[index] = newproperty; PedestrianData[index] = newdata; States[index] = newstate; } else { States[index] = new PedestrianState() { CoolDown = cd, State = currentState }; } }
public void Execute(int index) { PedestrianData thisPed = PedestrianData[index]; float rotateAngle = RdGen.NextFloat(-0.01f, 0.01f); float cos = math.cos(rotateAngle); float sin = math.sin(rotateAngle); float3 newDir = new float3() { x = thisPed.Forword.x * cos - thisPed.Forword.z * sin, y = 0, z = thisPed.Forword.x * sin + thisPed.Forword.z * cos }; float3 step = newDir * thisPed.Speed * DeltaTime; float2 newLocalPos = step.xz * math.rcp(TexelSize) + thisPed.LocalPos; int2 GridIdAdd = (int2)math.floor(newLocalPos); bool StillInCurrentTexel = GridIdAdd.x == 0 && GridIdAdd.y == 0; int2 newGridId = GridIdAdd + thisPed.GridId; float3 newWorldPos = thisPed.WorldPos; if (StillInCurrentTexel || IsWalkable(newGridId))//go ahead! { newLocalPos -= GridIdAdd; newWorldPos += step; } else //turn toward gradient! { newDir = Gradient(thisPed.GridId); newLocalPos = thisPed.LocalPos; } thisPed.Forword = newDir; thisPed.WorldPos = newWorldPos; thisPed.LocalPos = newLocalPos; thisPed.GridId = newGridId; PedestrianData[index] = thisPed; }