- Home /
Rigidbody.position causes shaking
int x = Screen.width / 2;
int y = Screen.height / 2;
GameObject Cube = GameObject.Find("Cube");
Ray ray = Camera.main.ScreenPointToRay(new Vector3(x, y));
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
Cube.rigidbody.position = hit.point;
Cube.rigidbody.velocity = new Vector3(0, 0, 0);
}
Cube has rigidbody in it.
Where does this happen? In Update()? On a click?
And what shakes - the Cube or something else?
We need a bit more information before we can give any input on your problem.
Generally ins$$anonymous$$d of setting the position of a rigidbody you want to use $$anonymous$$ovePosition. $$anonymous$$aybe that will help?
Answer by TheBeardPhantom · Sep 12, 2014 at 08:27 PM
I saw from your comments that you're doing this in the Update method.
Interactions with the physics engine (rigibodies, etc.) should ONLY be done in the FixedUpdate method.
http://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html
Also, according to the documentation for Rigidbody.position:
This is similar to setting transform.position, however the position will only be applied to the transform at the end of the physics step. If you want to continously move a rigidbody or kinematic rigidbody use MovePosition and MoveRotation instead.
Your answer
Follow this Question
Related Questions
Raycast exit point of collider 0 Answers
Another Raycast Issue. 0 Answers
Raycast Not Drawing In Target Direction 0 Answers
Help with Raycast C# 0 Answers
RaycastHit behind object 2 Answers