public virtual void Integrate(MovementOutput movement, float duration) { this.position.x += movement.linear.x * duration; this.position.y += movement.linear.y * duration; this.position.z += movement.linear.z * duration; this.orientation += movement.angular * duration; this.orientation = this.orientation % MathConstants.MATH_2PI; }
public virtual void Integrate(MovementOutput movement, float duration) { this.position.x += movement.linear.x*duration; this.position.y += movement.linear.y*duration; this.position.z += movement.linear.z*duration; this.orientation += movement.angular*duration; this.orientation = this.orientation%MathConstants.MATH_2PI; }
public override void Integrate(MovementOutput movement, float duration) { this.Integrate(duration); this.velocity.x += movement.linear.x * duration; this.velocity.y += movement.linear.y * duration; this.velocity.z += movement.linear.z * duration; this.rotation += movement.angular * duration; }
public override void Integrate(MovementOutput movement, float duration) { this.Integrate(duration); this.velocity.x += movement.linear.x*duration; this.velocity.y += movement.linear.y*duration; this.velocity.z += movement.linear.z*duration; this.rotation += movement.angular*duration; }
public virtual void Integrate(MovementOutput movement, float duration) { this.transform.position += movement.linear * duration; //this.transform.position.x += movement.linear.x*duration; //this.position.y += movement.linear.y*duration; //this.position.z += movement.linear.z*duration; this.Orientation += movement.angular * duration; this.Orientation = this.Orientation % MathConstants.MATH_2PI; this.transform.rotation = Quaternion.AngleAxis(this.Orientation * MathConstants.MATH_180_PI, Vector3.up); }
public override MovementOutput GetMovement() { var output = new MovementOutput(); output.linear = (this.MovingTarget.velocity - this.Character.velocity)/this.TimeToTargetSpeed; if (output.linear.sqrMagnitude > this.MaxAcceleration*this.MaxAcceleration) { output.linear = output.linear.normalized*this.MaxAcceleration; } output.angular = 0; //Debug.DrawRay(Character.position, output.linear, new Color(70 / 255, 15 / 255, 11 / 255)); return output; }
public void Integrate(MovementOutput steering, MovementOutput drag, float duration) { this.Integrate(duration); this.velocity.x *= (float)Math.Pow(drag.linear.x, duration); this.velocity.y *= (float)Math.Pow(drag.linear.y, duration); this.velocity.z *= (float)Math.Pow(drag.linear.z, duration); this.rotation *= (float)Math.Pow(drag.angular, duration); this.velocity.x += steering.linear.x * duration; this.velocity.y += steering.linear.y * duration; this.velocity.z += steering.linear.z * duration; this.rotation += steering.angular * duration; }
public void Integrate(MovementOutput steering, float drag, float duration) { this.Integrate(duration); var totalDrag = (float)Math.Pow(drag, duration); this.velocity *= totalDrag; this.rotation *= drag * drag; this.velocity.x += steering.linear.x * duration; this.velocity.y += steering.linear.y * duration; this.velocity.z += steering.linear.z * duration; this.rotation += steering.angular * duration; }
public void Integrate(MovementOutput steering, float drag, float duration) { this.Integrate(duration); var totalDrag = (float)Math.Pow(drag, duration); this.velocity *= totalDrag; this.rotation *= drag*drag; this.velocity.x += steering.linear.x * duration; this.velocity.y += steering.linear.y * duration; this.velocity.z += steering.linear.z * duration; this.rotation += steering.angular * duration; }
public void Integrate(MovementOutput steering, MovementOutput drag, float duration) { this.Integrate(duration); this.velocity.x *= (float)Math.Pow(drag.linear.x, duration); this.velocity.y *= (float) Math.Pow(drag.linear.y, duration); this.velocity.z *= (float) Math.Pow(drag.linear.z, duration); this.rotation *= (float)Math.Pow(drag.angular, duration); this.velocity.x += steering.linear.x * duration; this.velocity.y += steering.linear.y * duration; this.velocity.z += steering.linear.z * duration; this.rotation += steering.angular * duration; }
protected abstract MovementOutput FilterMovementOutput(MovementOutput output, DynamicCharacter character);
protected override MovementOutput FilterMovementOutput(MovementOutput output, DynamicCharacter character) { Vector3 charOrientation = MathHelper.ConvertOrientationToVector(character.KinematicData.orientation); float charSpeed = character.KinematicData.velocity.sqrMagnitude; float angleDiff = Mathf.Deg2Rad * (Vector3.Angle(charOrientation, output.linear)); float angleDiffAbs = Math.Abs(angleDiff); float distance = (GoalPosition - character.KinematicData.position).sqrMagnitude; if (character.BackingUp || angleDiffAbs >= MathConstants.MATH_PI - MathConstants.MATH_PI / 3f && charSpeed <= 1 && distance < 900f) // 900 = 30^2 { character.BackingUp = true; Vector3 contraryVector = MathHelper.ConvertOrientationToVector(MathHelper.ConvertVectorToOrientation((GoalPosition - character.KinematicData.position)) + MathConstants.MATH_PI); character.KinematicData.orientation = MathHelper.ConvertVectorToOrientation(Vector3.Lerp(charOrientation, contraryVector, 0.1f)); return output; } if (!character.BackingUp) { if (Physics.Raycast(character.KinematicData.position, character.KinematicData.velocity, 30f)) { //Debug.DrawLine(character.KinematicData.position, character.KinematicData.velocity.normalized*30f+character.KinematicData.position, Color.black); CapCharacterVelocity(character); } if (angleDiff > MathConstants.MATH_PI_2 / 6f && charSpeed >= 4900) // 4900 = 70^2 { output.linear = MathHelper.ConvertOrientationToVector(MathConstants.MATH_PI_2 / 6f).normalized; character.KinematicData.velocity = character.KinematicData.velocity.normalized * 40f; return output; } if (angleDiff > MathConstants.MATH_PI_2 / 3f && charSpeed >= 3600) // 3600 = 60^2 { output.linear = MathHelper.ConvertOrientationToVector(MathConstants.MATH_PI_2 / 3f).normalized; character.KinematicData.velocity = character.KinematicData.velocity.normalized * 30f; return output; } if (angleDiff > MathConstants.MATH_PI_4 && charSpeed >= 2500) // 2500 = 50^2 { output.linear = MathHelper.ConvertOrientationToVector(MathConstants.MATH_PI_4).normalized; character.KinematicData.velocity = character.KinematicData.velocity.normalized * 25f; return output; } if (angleDiffAbs >= MathConstants.MATH_PI_2 / 3f && charSpeed <= 100) // 100 = 10^2 { // aqui altera apenas a direcção em que em que o carro vira if (angleDiff < 0) { output.linear = MathHelper.ConvertOrientationToVector(character.KinematicData.orientation - MathConstants.MATH_PI_2 / 48f); character.KinematicData.velocity *= 2f; } else if (angleDiff >= 0) { output.linear = MathHelper.ConvertOrientationToVector(character.KinematicData.orientation + MathConstants.MATH_PI_2 / 48f); character.KinematicData.velocity *= 2f; } return output; } } return output; }
protected override MovementOutput FilterMovementOutput(MovementOutput output, DynamicCharacter character) { float charOrientation = character.KinematicData.orientation; float charSpeed = character.KinematicData.velocity.sqrMagnitude; float velocity = MathHelper.ConvertVectorToOrientation(output.linear); float angleDiff = MathHelper.SmallestDifferenceBetweenTwoAngles(charOrientation, velocity); // OPTIMIZACAO: trocar a divisao por multiplicacao if (angleDiff > MathConstants.MATH_PI_2 / 6f && charSpeed >= 729) // 729 = 27^2 { output.linear = MathHelper.ConvertOrientationToVector(MathConstants.MATH_PI_2 / 6f).normalized; character.KinematicData.velocity = character.KinematicData.velocity.normalized * 22f; return output; } if (angleDiff > MathConstants.MATH_PI_2 / 3f && charSpeed >= 484) // 484 = 22^2 { output.linear = MathHelper.ConvertOrientationToVector(MathConstants.MATH_PI_2 / 3f).normalized; character.KinematicData.velocity = character.KinematicData.velocity.normalized * 18f; return output; } if (angleDiff > MathConstants.MATH_PI_4 && charSpeed >= 289) // 289 = 17^2 { output.linear = MathHelper.ConvertOrientationToVector(MathConstants.MATH_PI_4).normalized; character.KinematicData.velocity = character.KinematicData.velocity.normalized * 15f; return output; } if (angleDiff > MathConstants.MATH_PI_2 && charSpeed >= 225) // 225 = 15^2 { output.linear = MathHelper.ConvertOrientationToVector(MathConstants.MATH_PI_2).normalized; character.KinematicData.velocity = character.KinematicData.velocity.normalized * 13f; return output; } return output; }