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); } }
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); } }
static MotorMotion[] create_motions(FReaction reaction) { var l = reaction.MotionsLength; var motions = new MotorMotion[l]; for (var i = 0; i < l; i++) { motions[i] = create_motion(reaction.Motions(i)); } return(motions); }
protected override void InnerApplyMotion(MotorMotion motion) { var layer_mask = 1 << LayerMask.NameToLayer(this._layer_mask); var vec = Vector3.zero; switch (this._axis_of_motion) { case Axis.X: vec = Vector3.right * motion.Strength; break; case Axis.Y: vec = -Vector3.up * motion.Strength; break; case Axis.Z: vec = -Vector3.forward * motion.Strength; break; case Axis.RotX: this.transform.Rotate(Vector3.left, motion.Strength, this._relative_to); break; case Axis.RotY: this.transform.Rotate(Vector3.up, motion.Strength, this._relative_to); break; case Axis.RotZ: this.transform.Rotate(Vector3.forward, motion.Strength, this._relative_to); break; default: break; } 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); } }
public void ApplyMotion(MotorMotion motion) { if (this.Debugging) { print("Applying " + motion + " To " + this.name); } if (motion.Strength < this.MotionValueSpace.MinValue || motion.Strength > this.MotionValueSpace.MaxValue) { print( string.Format( "It does not accept input {0}, outside allowed range {1} to {2}", motion.Strength, this.MotionValueSpace.MinValue, this.MotionValueSpace.MaxValue)); return; // Do nothing } this.InnerApplyMotion(motion); this.EnergySpendSinceReset += Mathf.Abs(this.EnergyCost * motion.Strength); }
void Update() { if (this._player_motions != null) { var motions = new List <MotorMotion> (); foreach (var player_motion in this._player_motions.Motions) { if (Input.GetKey(player_motion.Key)) { if (this.Debugging) { print( string.Format( "{0} {1} {2}", player_motion.Actor, player_motion.Motor, player_motion.Strength)); } var motion = new MotorMotion(player_motion.Actor, player_motion.Motor, player_motion.Strength); motions.Add(motion); } } var step = motions.Count > 0; var parameters = new ReactionParameters(true, step) { IsExternal = false }; var reaction = new Reaction(parameters, motions.ToArray(), null, null); this._manager.React(reaction); } else { if (this.Debugging) { print("No playermotions scriptable object assigned"); } } }
protected override void InnerApplyMotion(MotorMotion motion) { this._wheel_collider.steerAngle = motion.Strength; }
void Update() { if (Application.isPlaying) { if (this._states == null) { var reset_reaction_parameters = new ReactionParameters(reset: true); this._states = this._Manager.ReactAndCollectStates(new Reaction(reset_reaction_parameters, "all")); } var reset = false; if (this._player_motions != null) { this._motions.Clear(); if (this._player_motions._Motions != null) { foreach (var player_motion in this._player_motions._Motions) { if (Input.GetKey(player_motion._Key)) { if (this.Debugging) { Debug.Log($"{player_motion._Actor} {player_motion._Motor} {player_motion._Strength}"); } if (player_motion._Motor == "Reset") { reset = true; break; } var motion = new MotorMotion( player_motion._Actor, player_motion._Motor, player_motion._Strength); this._motions.Add(motion); } } } if (reset) { var reset_reaction_parameters = new ReactionParameters(reset: true); this._states = this._Manager.ReactAndCollectStates(new Reaction(reset_reaction_parameters, "all")); } else { var step = this._motions.Count > 0; if (step) { foreach (var state in this._states) { if (this._auto_reset && state.Terminated) { var reset_reaction = new ReactionParameters(reset: true) { IsExternal = false }; this._Manager.ReactAndCollectStates(new Reaction(reset_reaction, state.EnvironmentName)); } } var parameters = new ReactionParameters(true, true, episode_count: true) { IsExternal = false }; var reaction = new Reaction(parameters, this._motions.ToArray(), null, null, null, ""); this._states = this._Manager.ReactAndCollectStates(reaction); } } } else { if (this.Debugging) { Debug.Log("No PlayerMotions ScriptableObject assigned"); } } } }
protected virtual void InnerApplyMotion(MotorMotion motion) { }
public static void updateMotor(LegController lc, HingeJoint2D j, MotorMotion m) { switch (m) { case MotorMotion.FREE: j.useMotor = false; break; case MotorMotion.BACKWARD: j.useMotor = true; j.motor = lc.opposedMotor; break; case MotorMotion.FORWARD: j.useMotor = true; j.motor = lc.walkMotor; break; case MotorMotion.SET: j.useMotor = true; j.motor = lc.setMotor; break; default: break; } }
public static void updateMotors(LegController lc, Leg l, MotorMotion h2k, MotorMotion k2f) { updateMotor(lc, l.rootToBend,h2k); updateMotor(lc, l.bendToEnd,k2f); l.state = "HipKnee: " + h2k + ", KneeFoot: " + k2f; }
protected override void InnerApplyMotion(MotorMotion motion) { if (motion.Strength < this.MotionValueSpace.MinValue || motion.Strength > this.MotionValueSpace.MaxValue) { print( string.Format( "It does not accept input {0}, outside allowed range {1} to {2}", motion.Strength, this.MotionValueSpace.MinValue, this.MotionValueSpace.MaxValue)); return; // Do nothing } switch (this._axis_of_motion) { case Axis.X: if (this._relative_to == Space.World) { this._rigidbody.AddForce(Vector3.left * motion.Strength); } else { this._rigidbody.AddRelativeForce(Vector3.left * motion.Strength); } break; case Axis.Y: if (this._relative_to == Space.World) { this._rigidbody.AddForce(Vector3.up * motion.Strength); } else { this._rigidbody.AddRelativeForce(Vector3.up * motion.Strength); } break; case Axis.Z: if (this._relative_to == Space.World) { this._rigidbody.AddForce(Vector3.forward * motion.Strength); } else { this._rigidbody.AddRelativeForce(Vector3.up * motion.Strength); } break; case Axis.RotX: if (this._relative_to == Space.World) { this._rigidbody.AddTorque(Vector3.left * motion.Strength); } else { this._rigidbody.AddRelativeTorque(Vector3.left * motion.Strength); } break; case Axis.RotY: if (this._relative_to == Space.World) { this._rigidbody.AddTorque(Vector3.up * motion.Strength); } else { this._rigidbody.AddRelativeTorque(Vector3.up * motion.Strength); } break; case Axis.RotZ: if (this._relative_to == Space.World) { this._rigidbody.AddTorque(Vector3.forward * motion.Strength); } else { this._rigidbody.AddRelativeTorque(Vector3.forward * motion.Strength); } break; default: break; } this._fired_this_step = true; }
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); } } }