- Home /
How do I push an object to a mouse specified location, and can i specify the speed it travels?
I have a first person camera on a plane with a static sphere. I am looking to be able to 'push' the sphere along the plane to where the mouse is pointing.
I would like this to happen only when the fpc is standing next to the sphere - like the player is guiding the sphere to a specific location.
Is there a known way to code 'pushing' like this?
I am new to this, but I want to learn!
Thanks for reading and for any help you can offer.
Answer by LyanApps · Apr 02, 2013 at 06:49 PM
You could add a rigidbody to your player object and set the rigidbody to iskinematic. http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-isKinematic.html
Then give the ball a rigidbody as well. Assuming both have colliders, then you can use player.Translate(player.forward * Time.deltaTime)
and the two physics objects should 'push' against each other.
Advanced: If you don't want the ball to roll away, you can change the sphere's rigid object to either have a much larger mass (harder to push) or or higher angularDrag (stops rolling more quickly).
Answer by Nightbadger · Apr 02, 2013 at 08:47 PM
Nice one, thanks!
I'll get experimenting now, thanks again.
No problem. If you like my answer would you $$anonymous$$d selecting it as the correct one?
Your answer
Follow this Question
Related Questions
Neighboring grid slots on a cube sphere? 0 Answers
Cube starts shaking when placed on a giant sphere 1 Answer
push the player back? 1 Answer
Scatter objects on a sphere (or another object) 1 Answer
RayCast to all directions 4 Answers