- Home /
Moving this object?
Hello, I'm trying to make a ship in the ocean and it has to collide with the continents, but I can't get it to move good, with transform.translate it ignores the colliders and I tried using rigidbody.MoveTowards but then I can't control the rigidbody's direction this is my script:
function Update () {
rigidbody.rotation = transform.rotation;
var forward = Vector3.right * -Speed;
if(Input.GetAxis("Vertical")){
transform.rigidbody.MovePosition(rigidbody.position + forward * Time.deltaTime);
}
var rotate = Input.GetAxis("Horizontal") * RotSpeed * Time.deltaTime;
transform.Rotate(0, rotate, 0);
}
I need to finish this pretty quick so plz react quickly, thanks in advance.
Hybris
SOLVED: What I did is combine transform.translate with a rigidbody component to the object, I gave the rigidbody a "mass" of "Infinity" and disabled "use gravity"
Thank you guys for answering so quick.
SOLVED: What I did is combine transform.translate with a rigidbody component to the object, I gave the rigidbody a "mass" of "Infinity" and disabled "use gravity"
Ps: This was for the people to lazy to read my question. XD
Answer by AlucardJay · Mar 22, 2012 at 03:52 PM
To 'push' rigidbody's around : http://unity3d.com/support/documentation/ScriptReference/Rigidbody.AddForce.html
if(Input.GetAxis("Vertical")){
rigidbody.AddForce (forward * Time.deltaTime);
}
I can't steer and you keep going forward if you pressed once.
so there is no drag with a ship in water ? and you are using rigidbody ?
To push the ship , use AddForce : http://unity3d.com/support/documentation/ScriptReference/Rigidbody.AddForce.html
To turn the ship , use AddTorque : http://unity3d.com/support/documentation/ScriptReference/Rigidbody.AddForce.html
or , if you are not using the physics : http://unity3d.com/support/documentation/ScriptReference/CharacterController.$$anonymous$$ove.html
I can't use AddForce cuz I lose the control over the object. I tried the character controller it doesn't work, I fall down. I will look in the AddTorque. This question is solved, but just keep throwing answers here, that way we will keep learning! yay! XD
Your answer
Follow this Question
Related Questions
Why is my object not following my path ?,Why is my object going through the target ? 2 Answers
Cant fall down while moving. 1 Answer
Prevent Player to push Rigidbody 0 Answers
Light bulb moving HELP 1 Answer
Something on a moving platform 2 Answers