IEnumerator behaviorGen() { var movable = GetComponent <DynamicPhysicsComponent>(); while (true) { float walk_time = RandomGen.NextFloat(150, 600); movable.move_direction = Direction.Right; for (float t = 0; t < walk_time; t += current_dt) { yield return(null); } movable.move_direction = Direction.None; for (float t = 0; t < RandomGen.NextFloat(700, 2000); t += current_dt) { yield return(null); } movable.move_direction = Direction.Left; for (float t = 0; t < walk_time; t += current_dt) { yield return(null); } movable.move_direction = Direction.None; for (float t = 0; t < RandomGen.NextFloat(700, 2000); t += current_dt) { yield return(null); } } }
public void GenerateSpark() { var movable = GetComponent <ProjectileMoveComponent>(); float x = RandomGen.NextFloat(-1.5f, 1.5f), y = RandomGen.NextFloat(-1.5f, 1.5f); var spark = new Particle(movable.WorldPosition.Coords); var s_movable = (DynamicPhysicsComponent)spark; s_movable.ApplyImpulse(new Vector2(x, y)); Game.AddToMainScene(spark); }
IEnumerator behaviorGen() { var movable = GetComponent <DynamicPhysicsComponent>(); while (true) { float wait_time = RandomGen.NextFloat(2, 8); for (float t = 0; t < wait_time; t += current_dt) { yield return(null); } GenerateSpark(); } }
public void GetNextRandomPosition(out float3 position, out quaternion rotation, out float3 direction, out float speed, out int currentid, out float lerpPos, out float dir, out int lane) { currentid = RandomGen.NextInt(0, RoadSegments.Count); int fromid = RoadSegments[currentid].StartNodeId; int toid = RoadSegments[currentid].EndNodeId; float laneWidth = RoadSegments[currentid].LaneWidth; int laneCount = RoadSegments[currentid].LaneNumber; lane = RandomGen.NextInt(0, laneCount); Vector3 roadVec = RoadSegments[currentid].Direction; dir = RoadSegments[currentid].IsOneWay == 1 ? 1.0f : (RandomGen.NextInt(0, 2) - 0.5f) * 2.0f; roadVec *= dir; direction = roadVec.normalized; float3 offsetDir = math.cross(direction, new float3() { x = 0, y = 1, z = 0 }); float offset = (lane + 0.5f) * laneWidth; if (RoadSegments[currentid].IsOneWay == 1) { offset -= (laneCount / 2.0f) * laneWidth; } lerpPos = RandomGen.NextFloat(0, 1); position = RoadNodes[toid].Position * lerpPos + RoadNodes[fromid].Position * (1.0f - lerpPos); position += offsetDir * offset; Quaternion facing = Quaternion.LookRotation(roadVec, Vector3.up); rotation = facing; float2 speedRange = GetSpeedRange(RoadSegments[currentid].Level); speed = RandomGen.NextFloat(speedRange.x, speedRange.y); speed /= 3.6f;//km/h to m/s; }