Movement using rigidbody.velocity to apply a constant force until stop

I am trying to make a constant force of a ship sailing using velocity. I got the movement down, but I am trying to make it only go FORWARD. As in the way the ship is pointing. Not where ever the user is pointing. I got no idea how to do this and I’ve tried several ways to see if I can.

#pragma strict

function Start () {

}
var move : GameObject;

private var speed: float;
private var turnSpeed: float;
private var interaction: String; //interaction type
private var ship: String;
function Update () {
	interaction = GameObject.Find("First Person Controller").GetComponent(Interactions).interaction; //Check interaction
	speed = 100;
	turnSpeed = 10;
	ship = GameObject.Find("First Person Controller").GetComponent(Interactions).Helm;
	move = GameObject.Find(ship);
		if (Input.GetKey(KeyCode.W) && interaction == "Helm") {
			move.rigidbody.velocity = transform.TransformDirection(Vector3.forward * speed); // Add a forward motion onto it.
		}

}

velocity is an actual speed. It SOUNDS LIKE you want to increase or decrease speed.

AddForce does thats

velocity doesnt increase or decrease. It sets.

If i had an object traveling 300 meters per second and i set velocity = 0 it would stop INSTANTLY no slowing down. If i then set it to 500 meters per second it would Instantly begin traveling that fast without having gone any slower in between.

to increase speed

rigidbody.AddForce(direction * speed)

OR IN YOUR CASE

rididbody.AddForce(tranform.forward * meters per second)

now you’ll need to add a limiting check to ensure speed doesnt exceed a certain limit.

velocity gives you the meters per second it is traveling in each of the 3 axis’s

since your always adding force in the forward axis you could do a simple speed check via

MaxSpeed = transform.forward * MaxSpeedInMetersPerSecond;

if rigidbody.velocity > MaxSpeed
rigidbody.velocity = MaxSpeed;

NOW REMEMBER ITS METERS PER SECOND
if you want your physics sim to work out right and lets say you want 60 miles per hour as your speed, your going to have to convert, unity speed is always meters per second. You keep that in mind for the purposes of keeping stuff relative.
You don’t want a boat going 60 meters per second and a human 40 because first off thats a stupid fast boat and secondly that is an even more stupid fast human. If you don’t give things realistic speeds then the physics that comes out of those calculations wont be realistic. Collisions might look crazy because your boat is traveling crazy fast.
You can have a 60 meters per second object but it will behave as such in calculations. Thats why you can’t just say oh its 60 whatever per whatever, because the force applied in a collision for example is meters per second.

mark as answerd and have a nice day :slight_smile: