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"); } } }
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); } }
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); } }
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); } } } }
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); } } }