I’m trying to make a little sailing simulation. I’m not interested in dead-on realistic physics, just something that approximates the feeling. So far I’ve just got movement speed and turn rate based on mouse position:
var speedSensitivity = 1;
var rudderSensitivity = 1;
function Update () {
//Get the mouse position and convert it to a manageable number with 0,0 being the center of the screen
var mouseY = ((Input.mousePosition.y - (Screen.height / 2)) / Screen.height)*512;
var mouseX = ((Input.mousePosition.x - (Screen.width / 2)) / Screen.width)*32;
//Adjust the values to the sensitivity sliders
var forwardForce = mouseY * Time.deltaTime * speedSensitivity;
var rotationForce = mouseX * Time.deltaTime * rudderSensitivity;
//Add forwardForce to the forward direction of the rigidbody
rigidbody.AddRelativeForce(Vector3.forward * forwardForce);
//Turn by rotationForce
transform.Rotate(0,rotationForce,0);
}
This script works fine for my purposes, but I want to adjust the turn rate based on how fast the ship is moving forward—so at 0 speed, it doesn’t turn at all, and at high speed, it turns a lot (emulating how a rudder works). I gather I need to multiply the rotationForce by some amount of either the absolute velocity or forward velocity of the rigidbody, but how do I detect those values?
P.S. Pretty much total newbie to both programming and Unity; please forgive me if I’ve missed something totally obvious! ![]()