Question by
mohamadghorab · Dec 31, 2019 at 07:48 AM ·
c#collisionrigidbodyplayermouseposition
how to add rigidbody to my mouseposition
i am trying to move my gameobject with my mouse but when i made it my rigidbody isn't working i tryied to make it but every single time it failed : rb = GetComponent(); rb.isKinematic = true;
if (useInitalCameraDistance)
{
Vector3 toobjectvector = transform.position - Camera.main.transform.position;
Vector3 lineardistancevector = Vector3.Project(toobjectvector,Camera.main.transform.forward);
actualDistance = lineardistancevector.magnitude;
}
else
{
actualDistance = distance;
}
}
void FixedUpdate ()
{
Vector3 mouseposition = Input.mousePosition;
mouseposition.z = actualDistance;
transform.position = Camera.main.ScreenToWorldPoint(mouseposition);
}
Comment
Answer by lgarczyn · Jan 02, 2020 at 01:59 AM
Don't use transform.position
, but rb.MovePosition
.
In general, you should never move a rigidbody using its transform.
Your answer
Follow this Question
Related Questions
Network Rigidbodies act weird? 0 Answers
Rigidbody velocity and AddForce overrides,Rigidbody.velocity overrides the Force 0 Answers
How to Change Rigidbody Type OnCollision/Trigger with Script? 1 Answer
Rigid Body and Collision 1 Answer
My player invisble to other players but i can still see other players 1 Answer