help with transform.position and rotation.

Hellow all,

I could really use some help. I have a boat and I am trying to move it forward by inrements of 2. My problem is that the boat is rotated on the y axis by 35 degrees so when i move it forward it moves slightly diagonal. Can anyone point me in the right direction on how to move it forward and include the angle of rotation on the y axis so that the boat moves in a straight line? Any help would be appreciated.

Thanks

I’m confused about your boat and its rotation. Are you saying it’s been modeled such that its own axes aren’t aligned with the boat itself? If that’s the case (the z-axis isn’t aligned with the beam of the boat) then you need to either (a) remodel it to align those, (b) child the boat model to an empty game object that is aligned nicely, or (c) figure out exactly what the offset is so you can use that value instead.

Otherwise maybe this is a question of using local versus world coordinates if the model’s axes are in fact properly aligned with its geometry. What’s the code you’re using if that’s the case?

Thanks for the reply. The axis of the model is correct. my problem is that when I place the boat on the water and align it with the dock I have to rotate the object on the y axis by 35 degrees. so when I try to move it forward the boat moves diagonal. I have tried everything to determine the rotation of the boat and have not been successful.

Thanks again for the help.

If the script is on the boat, just use transform.forward * speed. The boat’s forward vector is built-in and rotates with it.

You were probably using Vector3.forward.

+1

Vector3.forward will give you a generic world-relative forward direction ( 0,0,1 ). Instead, transform.forward will give you the boat’s forward direction (the boat’s local z-axis) which is what you really want.

Thanks everyone. This works great now.

I have the same problem and I’ve tried transform.forward but it doesn’t move… Here is the code

function Update () {
	
	if(inainte)
	{
		transform.forward* engineSpeed;
	}
	else
	{
		curentPosition = transform.localPosition;
	}
	
	if(inapoi)
	{
		transform.forward * (-1) * thrustSpeed;
	}
	else
	{
		curentPosition = transform.localPosition;
	}

do i have to enter something else or to declare?

solved using transform.Translate(transform.forward * Time.deltaTime); so might be good to make a more elaborated manual or wiki for such important noob issues :stuck_out_tongue: