예제 #1
0
파일: Entity.cs 프로젝트: rbarraud/blarg4
 public DVector3 RandomSpawnPosition(DReal min, DReal max)
 {
     for (var attempt = 0; attempt < 100; attempt += 1)
     {
         var angle  = World.current.RandomValue() * 360;
         var radius = World.current.RandomRange(min, max);
         var x      = this.position.x + DReal.Cos(angle) * radius;
         var z      = this.position.z + DReal.Sin(angle) * radius;
         var height = World.current.map.Height(new DVector3(x, 0, z));
         var p      = new DVector3(x, height, z);
         if (World.current.navigation.Reachability(this.position) == World.current.navigation.Reachability(p))
         {
             return(p);
         }
     }
     UnityEngine.Debug.Log("Failed to generate random position.");
     return(this.position);
 }
예제 #2
0
        public override void OnTick()
        {
            var p2d  = new DVector3(entity.position.x, 0, entity.position.z);
            var targ = new Game.DVector3(target.x, 0, target.z);
            var dist = World.current.map.Distance(p2d, targ);
            var dir  = World.current.map.Direction(p2d, targ);

            if (dist < moveSpeed * World.deltaTime)
            {
                entity.position = new DVector3(target.x, entity.position.y, target.z);
            }
            else
            {
                var d = p2d + dir * moveSpeed * World.deltaTime;
                entity.position      = new DVector3(d.x, entity.position.y, d.z);
                entity.faceDirection = dir;
            }

            var terrainHeight = DReal.Max(0, World.current.map.Height(entity.position));
            var wobble        = DReal.Sin((World.current.time + wobbleOffset) * wobbleFrequency) * wobbleAmplitude;
            var targetHeight  = terrainHeight + floatOffset + wobble;

            var height_diff = DReal.Abs(targetHeight - entity.position.y);
            var newHeight   = (DReal)0;

            if (targetHeight > entity.position.y)
            {
                newHeight = entity.position.y + DReal.Min(height_diff, verticalSpeed * World.deltaTime);
            }
            else
            {
                newHeight = entity.position.y - DReal.Min(height_diff, verticalSpeed * World.deltaTime);
            }

            entity.position = new DVector3(entity.position.x,
                                           DReal.Max(terrainHeight, newHeight),
                                           entity.position.z);
        }
예제 #3
0
 public static DVector2 FromAngle(DReal radians)
 {
     return(new DVector2(DReal.Cos(radians), DReal.Sin(radians)));
 }