/// <inheritdoc /> /// <summary> /// </summary> /// <param name="motion"></param> protected override void InnerApplyMotion(IMotorMotion motion) { foreach (var indicator in this._indicators) { indicator.color = this._inactive_color; } var index = (int)motion.Strength; #if NEODROID_DEBUG if (this.Debugging) { Debug.Log($"MultiArmedBandit got index {index}"); } #endif this._last_index = index; var random_value = Random.Range(0f, 1f); if (random_value <= this._win_likelihoods[this._last_index]) { this._indicators[this._last_index].color = this._win_color; this._won = true; } else { this._indicators[this._last_index].color = this._lose_color; this._won = false; } }
/// <inheritdoc /> /// <summary> /// </summary> /// <param name="motion"></param> /// <exception cref="T:System.ArgumentOutOfRangeException"></exception> protected override void InnerApplyMotion(IMotorMotion motion) { if (this._material) { switch ((int)motion.Strength) { case 1: this._material.color = Color.blue; break; case 2: this._material.color = Color.black; break; case 3: this._material.color = Color.red; break; case 4: this._material.color = Color.green; break; default: throw new ArgumentOutOfRangeException(); } } }
/// <inheritdoc /> /// <summary> /// </summary> /// <param name="motion"></param> protected override void InnerApplyMotion(IMotorMotion motion) { if (motion.MotorName == this._x) { this.transform.Translate(Vector3.left * motion.Strength, this._Relative_To); } else if (motion.MotorName == this._y) { this.transform.Translate(-Vector3.up * motion.Strength, this._Relative_To); } else if (motion.MotorName == this._z) { this.transform.Translate(-Vector3.forward * motion.Strength, this._Relative_To); } else if (motion.MotorName == this._rot_x) { this.transform.Rotate(Vector3.left, motion.Strength, this._Relative_To); } else if (motion.MotorName == this._rot_y) { this.transform.Rotate(Vector3.up, motion.Strength, this._Relative_To); } else if (motion.MotorName == this._rot_z) { this.transform.Rotate(Vector3.forward, motion.Strength, this._Relative_To); } }
/// <inheritdoc /> /// <summary> /// </summary> /// <param name="motion"></param> protected override void InnerApplyMotion(IMotorMotion motion) { if (motion.MotorName == this._movement) { this.ApplyMovement(motion.Strength); } else if (motion.MotorName == this._turn) { this.ApplyRotation(motion.Strength); } }
static IMotorMotion[] deserialise_motions(FReaction reaction) { var l = reaction.MotionsLength; var motions = new IMotorMotion[l]; for (var i = 0; i < l; i++) { motions[i] = deserialise_motion(reaction.Motions(i)); } return(motions); }
protected override void InnerApplyMotion(IMotorMotion motion) { var layer_mask = 1 << LayerMask.NameToLayer(this._Layer_Mask); var vec = Vector3.zero; switch (this._Axis_Of_Motion) { case Axis.X_: // Translational vec = Vector3.right * motion.Strength; break; case Axis.Y_: // Translational vec = -Vector3.up * motion.Strength; break; case Axis.Z_: // Translational vec = -Vector3.forward * motion.Strength; break; case Axis.Rot_x_: // Rotational this.transform.Rotate(Vector3.left, motion.Strength, this._Relative_To); break; case Axis.Rot_y_: // Rotational this.transform.Rotate(Vector3.up, motion.Strength, this._Relative_To); break; case Axis.Rot_z_: // Rotational this.transform.Rotate(Vector3.forward, motion.Strength, this._Relative_To); break; case Axis.Dir_x_: break; case Axis.Dir_y_: break; case Axis.Dir_z_: break; default: throw new ArgumentOutOfRangeException(); } 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 override void ApplyMotion(IMotorMotion motion) { if (this._is_alive) { base.ApplyMotion(motion); } else { #if NEODROID_DEBUG if (this.Debugging) { Debug.Log("Actor is dead, cannot apply motion"); } #endif } }
protected override void InnerApplyMotion(IMotorMotion motion) { var layer_mask = 1 << LayerMask.NameToLayer(this._Layer_Mask); Vector3 vec; switch ((int)motion.Strength) { case 1: vec = Vector3.forward; break; case 2: vec = Vector3.back; break; case 3: vec = Vector3.left; break; case 4: vec = Vector3.right; break; default: throw new ArgumentOutOfRangeException(); } 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); } }
/// <summary> /// /// </summary> /// <param name="motion"></param> public void ApplyMotion(IMotorMotion motion) { #if NEODROID_DEBUG if (this.Debugging) { Debug.Log("Applying " + motion + " To " + this.name); } #endif if (motion.Strength < this.MotionValueSpace._Min_Value || motion.Strength > this.MotionValueSpace._Max_Value) { Debug.LogWarning( $"It does not accept input {motion.Strength}, outside the allowed range from {this.MotionValueSpace._Min_Value} to {this.MotionValueSpace._Max_Value}"); return; // Do nothing } motion.Strength = this._motion_value_space.Round(motion.Strength); this.InnerApplyMotion(motion); this.EnergySpendSinceReset += Mathf.Abs(this.EnergyCost * motion.Strength); }
/// <summary> /// </summary> /// <param name="motion"></param> public virtual void ApplyMotion(IMotorMotion motion) { #if NEODROID_DEBUG if (this.Debugging) { Debug.Log("Applying " + motion + " To " + this.name + "'s motors"); } #endif var motion_motor_name = motion.MotorName; if (this._Motors.ContainsKey(motion_motor_name) && this._Motors[motion_motor_name] != null) { this._Motors[motion_motor_name].ApplyMotion(motion); } else { #if NEODROID_DEBUG if (this.Debugging) { Debug.Log("Could find not motor with the specified name: " + motion_motor_name); } #endif } }
/// <inheritdoc /> /// <summary> /// </summary> /// <param name="motion"></param> protected override void InnerApplyMotion(IMotorMotion motion) { if (motion.Strength < this.MotionValueSpace._Min_Value || motion.Strength > this.MotionValueSpace._Max_Value) { Debug.Log( $"It does not accept input {motion.Strength}, outside allowed range {this.MotionValueSpace._Min_Value} to {this.MotionValueSpace._Max_Value}"); 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.forward * motion.Strength); } break; case Axis.Rot_x_: if (this._Relative_To == Space.World) { this._Rigidbody.AddTorque(Vector3.left * motion.Strength); } else { this._Rigidbody.AddRelativeTorque(Vector3.left * motion.Strength); } break; case Axis.Rot_y_: if (this._Relative_To == Space.World) { this._Rigidbody.AddTorque(Vector3.up * motion.Strength); } else { this._Rigidbody.AddRelativeTorque(Vector3.up * motion.Strength); } break; case Axis.Rot_z_: if (this._Relative_To == Space.World) { this._Rigidbody.AddTorque(Vector3.forward * motion.Strength); } else { this._Rigidbody.AddRelativeTorque(Vector3.forward * motion.Strength); } break; case Axis.Dir_x_: break; case Axis.Dir_y_: break; case Axis.Dir_z_: break; default: throw new ArgumentOutOfRangeException(); } this._fired_this_step = true; }
/// <summary> /// /// </summary> /// <param name="motion"></param> protected override void InnerApplyMotion(IMotorMotion motion) { if (this._Relative_To == Space.World) { if (motion.MotorName == this._x) { this._Rigidbody.AddForce(Vector3.left * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._y) { this._Rigidbody.AddForce(Vector3.up * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._z) { this._Rigidbody.AddForce(Vector3.forward * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._rot_x) { this._Rigidbody.AddTorque(Vector3.left * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._rot_y) { this._Rigidbody.AddTorque(Vector3.up * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._rot_z) { this._Rigidbody.AddTorque(Vector3.forward * motion.Strength, this._ForceMode); } } else if (this._Relative_To == Space.Self) { if (motion.MotorName == this._x) { this._Rigidbody.AddRelativeForce(Vector3.left * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._y) { this._Rigidbody.AddRelativeForce(Vector3.up * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._z) { this._Rigidbody.AddRelativeForce(Vector3.forward * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._rot_x) { this._Rigidbody.AddRelativeTorque(Vector3.left * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._rot_y) { this._Rigidbody.AddRelativeTorque(Vector3.up * motion.Strength, this._ForceMode); } else if (motion.MotorName == this._rot_z) { this._Rigidbody.AddRelativeTorque(Vector3.forward * motion.Strength, this._ForceMode); } } else { Debug.LogWarning($"Not applying force in space {this._Relative_To}"); } }
/// <inheritdoc /> /// <summary> /// </summary> protected override void InnerApplyMotion(IMotorMotion motion) { this._wheel_collider.motorTorque = motion.Strength; }
/// <summary> /// </summary> /// <param name="motion"></param> protected override void InnerApplyMotion(IMotorMotion motion) { if (!this._Angular_Motors) { if (motion.MotorName == this._x) { if (this._Relative_To == Space.World) { this._Rigidbody.AddForce(Vector3.left * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeForce(Vector3.left * motion.Strength, this._ForceMode); } } else if (motion.MotorName == this._y) { if (this._Relative_To == Space.World) { this._Rigidbody.AddForce(Vector3.up * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeForce(Vector3.up * motion.Strength, this._ForceMode); } } else if (motion.MotorName == this._z) { if (this._Relative_To == Space.World) { this._Rigidbody.AddForce(Vector3.forward * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeForce(Vector3.forward * motion.Strength, this._ForceMode); } } } else { if (motion.MotorName == this._x) { if (this._Relative_To == Space.World) { this._Rigidbody.AddTorque(Vector3.left * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeTorque(Vector3.left * motion.Strength, this._ForceMode); } } else if (motion.MotorName == this._y) { if (this._Relative_To == Space.World) { this._Rigidbody.AddTorque(Vector3.up * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeTorque(Vector3.up * motion.Strength, this._ForceMode); } } else if (motion.MotorName == this._z) { if (this._Relative_To == Space.World) { this._Rigidbody.AddTorque(Vector3.forward * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeTorque(Vector3.forward * motion.Strength, this._ForceMode); } } } }
/// <summary> /// /// </summary> /// <param name="motion"></param> protected abstract void InnerApplyMotion(IMotorMotion motion);
/// <summary> /// </summary> /// <param name="motion"></param> /// <exception cref="ArgumentOutOfRangeException"></exception> protected override void InnerApplyMotion(IMotorMotion motion) { switch (this._Axis_Of_Motion) { case Axis.X_: if (this._Relative_To == Space.World) { this._Rigidbody.AddForce(Vector3.left * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeForce(Vector3.left * motion.Strength, this._ForceMode); } break; case Axis.Y_: if (this._Relative_To == Space.World) { this._Rigidbody.AddForce(Vector3.up * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeForce(Vector3.up * motion.Strength, this._ForceMode); } break; case Axis.Z_: if (this._Relative_To == Space.World) { this._Rigidbody.AddForce(Vector3.forward * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeForce(Vector3.forward * motion.Strength, this._ForceMode); } break; case Axis.Rot_x_: if (this._Relative_To == Space.World) { this._Rigidbody.AddTorque(Vector3.left * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeTorque(Vector3.left * motion.Strength, this._ForceMode); } break; case Axis.Rot_y_: if (this._Relative_To == Space.World) { this._Rigidbody.AddTorque(Vector3.up * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeTorque(Vector3.up * motion.Strength, this._ForceMode); } break; case Axis.Rot_z_: if (this._Relative_To == Space.World) { this._Rigidbody.AddTorque(Vector3.forward * motion.Strength, this._ForceMode); } else { this._Rigidbody.AddRelativeTorque(Vector3.forward * motion.Strength, this._ForceMode); } break; case Axis.Dir_x_: break; case Axis.Dir_y_: break; case Axis.Dir_z_: break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// </summary> /// <param name="motion"></param> protected override void InnerApplyMotion(IMotorMotion motion) { var layer_mask = 1 << LayerMask.NameToLayer(this._Layer_Mask); if (!this._Rotational_Motors) { if (motion.MotorName == 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.MotorName == 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.MotorName == 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.MotorName == this._x) { this.transform.Rotate(Vector3.left, motion.Strength, this._Relative_To); } else if (motion.MotorName == this._y) { this.transform.Rotate(Vector3.up, motion.Strength, this._Relative_To); } else if (motion.MotorName == this._z) { this.transform.Rotate(Vector3.forward, motion.Strength, this._Relative_To); } } }