- Home /
Rotating a boat on two axes with force.
var strength : float = 10.0f; var damping : float = 10.0; function Update () { if(Input.GetKeyDown(KeyCode.Mouse0)) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hit : RaycastHit;
if (Physics.Raycast(ray, hit))
{
var delta = transform.position - hit.point ;
rigidbody.AddForce(delta.normalized * strength, ForceMode.Impulse);
// Look at and dampen the rotation
var lookDirection = Quaternion.LookRotation(hit.point - transform.position);
lookDirection.y = 0;
Quaternion targetRotation = Quaternion.LookRotation(lookDirection,Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * damping);
}
}
}
This is the code i used to let a boat move when clicking on a plane, to keep it look like the boat moves when we create ripple. Force works fine. But there is some problem with the spinning part.
Quaternion targetRotation = Quaternion.LookRotation(lookDirection,Vector3.up);
This part alone says some semi colon error. Please help me in discovering what error it is.. thanks.
Answer by Rally Raghavan · Mar 18, 2011 at 07:09 AM
I found the answer on my own. the error is rectified.
var rotation = Quaternion.LookRotation(hit.point - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
this is the proper code.
Answer by efge · Mar 13, 2011 at 10:31 PM
It tries to split this line into two (no matter if it is useful or not):
Quaternion;
and
targetRotation = Quaternion.LookRotation(lookDirection,Vector3.up);
No, this answer didn't work out.. It showed one more just one more error.
Your answer
Follow this Question
Related Questions
Rotate Gameobject by vertex shader with quaternion 0 Answers
AirPlane-Like Rotation ( like in GTA games) 1 Answer
How can i flip a ragdoll ? 1 Answer
Add force at position Question 1 Answer