예제 #1
0
파일: Actor.cs 프로젝트: DanielLSM/droid
 public void ApplyMotion(MotorMotion motion)
 {
     if (this._alive)
     {
         if (this.Debugging)
         {
             print("Applying " + motion + " To " + this.name + "'s motors");
         }
         var motion_motor_name = motion.GetMotorName();
         if (this._motors.ContainsKey(motion_motor_name) && this._motors[motion_motor_name] != null)
         {
             this._motors[motion_motor_name].ApplyMotion(motion);
         }
         else
         {
             if (this.Debugging)
             {
                 print("Could find not motor with the specified name: " + motion_motor_name);
             }
         }
     }
     else
     {
         if (this.Debugging)
         {
             print("Actor is dead, cannot apply motion");
         }
     }
 }
예제 #2
0
 protected override void InnerApplyMotion(MotorMotion motion)
 {
     if (motion.GetMotorName() == this._x)
     {
         this.transform.Translate(Vector3.left * motion.Strength, this._relative_to);
     }
     else if (motion.GetMotorName() == this._y)
     {
         this.transform.Translate(-Vector3.up * motion.Strength, this._relative_to);
     }
     else if (motion.GetMotorName() == this._z)
     {
         this.transform.Translate(-Vector3.forward * motion.Strength, this._relative_to);
     }
     else if (motion.GetMotorName() == this._rot_x)
     {
         this.transform.Rotate(Vector3.left, motion.Strength, this._relative_to);
     }
     else if (motion.GetMotorName() == this._rot_y)
     {
         this.transform.Rotate(Vector3.up, motion.Strength, this._relative_to);
     }
     else if (motion.GetMotorName() == this._rot_z)
     {
         this.transform.Rotate(Vector3.forward, motion.Strength, this._relative_to);
     }
 }
예제 #3
0
 protected override void InnerApplyMotion(MotorMotion motion)
 {
     if (motion.GetMotorName() == this._x)
     {
         this._rigidbody.AddForce(Vector3.left * motion.Strength);
     }
     else if (motion.GetMotorName() == this._y)
     {
         this._rigidbody.AddForce(Vector3.up * motion.Strength);
     }
     else if (motion.GetMotorName() == this._z)
     {
         this._rigidbody.AddForce(Vector3.forward * motion.Strength);
     }
     else if (motion.GetMotorName() == this._rot_x)
     {
         this._rigidbody.AddTorque(Vector3.left * motion.Strength);
     }
     else if (motion.GetMotorName() == this._rot_y)
     {
         this._rigidbody.AddTorque(Vector3.up * motion.Strength);
     }
     else if (motion.GetMotorName() == this._rot_z)
     {
         this._rigidbody.AddTorque(Vector3.forward * motion.Strength);
     }
 }
예제 #4
0
 protected override void InnerApplyMotion(MotorMotion motion)
 {
     if (!this._rotational_motors)
     {
         if (motion.GetMotorName() == this._x)
         {
             if (this._relative_to == Space.World)
             {
                 this._rigidbody.AddForce(Vector3.left * motion.Strength);
             }
             else
             {
                 this._rigidbody.AddRelativeForce(Vector3.left * motion.Strength);
             }
         }
         else if (motion.GetMotorName() == this._y)
         {
             if (this._relative_to == Space.World)
             {
                 this._rigidbody.AddForce(Vector3.up * motion.Strength);
             }
             else
             {
                 this._rigidbody.AddRelativeForce(Vector3.up * motion.Strength);
             }
         }
         else if (motion.GetMotorName() == this._z)
         {
             if (this._relative_to == Space.World)
             {
                 this._rigidbody.AddForce(Vector3.forward * motion.Strength);
             }
             else
             {
                 this._rigidbody.AddRelativeForce(Vector3.forward * motion.Strength);
             }
         }
     }
     else
     {
         if (motion.GetMotorName() == this._x)
         {
             if (this._relative_to == Space.World)
             {
                 this._rigidbody.AddTorque(Vector3.left * motion.Strength);
             }
             else
             {
                 this._rigidbody.AddRelativeTorque(Vector3.left * motion.Strength);
             }
         }
         else if (motion.GetMotorName() == this._y)
         {
             if (this._relative_to == Space.World)
             {
                 this._rigidbody.AddTorque(Vector3.up * motion.Strength);
             }
             else
             {
                 this._rigidbody.AddRelativeTorque(Vector3.up * motion.Strength);
             }
         }
         else if (motion.GetMotorName() == this._z)
         {
             if (this._relative_to == Space.World)
             {
                 this._rigidbody.AddTorque(Vector3.forward * motion.Strength);
             }
             else
             {
                 this._rigidbody.AddRelativeTorque(Vector3.forward * motion.Strength);
             }
         }
     }
 }
예제 #5
0
        protected override void InnerApplyMotion(MotorMotion motion)
        {
            var layer_mask = 1 << LayerMask.NameToLayer(this._layer_mask);

            if (!this._rotational_motors)
            {
                if (motion.GetMotorName() == this._x)
                {
                    var vec = Vector3.right * motion.Strength;
                    if (this._no_collisions)
                    {
                        if (!Physics.Raycast(this.transform.position, vec, Mathf.Abs(motion.Strength), layer_mask))
                        {
                            this.transform.Translate(vec, this._relative_to);
                        }
                    }
                    else
                    {
                        this.transform.Translate(vec, this._relative_to);
                    }
                }
                else if (motion.GetMotorName() == this._y)
                {
                    var vec = -Vector3.up * motion.Strength;
                    if (this._no_collisions)
                    {
                        if (!Physics.Raycast(this.transform.position, vec, Mathf.Abs(motion.Strength), layer_mask))
                        {
                            this.transform.Translate(vec, this._relative_to);
                        }
                    }
                    else
                    {
                        this.transform.Translate(vec, this._relative_to);
                    }
                }
                else if (motion.GetMotorName() == this._z)
                {
                    var vec = -Vector3.forward * motion.Strength;
                    if (this._no_collisions)
                    {
                        if (!Physics.Raycast(this.transform.position, vec, Mathf.Abs(motion.Strength), layer_mask))
                        {
                            this.transform.Translate(vec, this._relative_to);
                        }
                    }
                    else
                    {
                        this.transform.Translate(vec, this._relative_to);
                    }
                }
            }
            else
            {
                if (motion.GetMotorName() == this._x)
                {
                    this.transform.Rotate(Vector3.left, motion.Strength, this._relative_to);
                }
                else if (motion.GetMotorName() == this._y)
                {
                    this.transform.Rotate(Vector3.up, motion.Strength, this._relative_to);
                }
                else if (motion.GetMotorName() == this._z)
                {
                    this.transform.Rotate(Vector3.forward, motion.Strength, this._relative_to);
                }
            }
        }