- Home /
Have rigidbody always face camera the direction it had when it was picked up
I'm making Amnesia-like picking objects up mechanic. It's easy to just pick up objects and have them always in front of camera, but the part I'm having troubles with is the bit where the held object always faces the camera exactly the same direction it was facing the camera when it was picked up.
Here's an example: let's say there's a bottle standing on a table and neck of that bottle is facing ceilings (bottle is just standing on a table straight up). When I pick this bottle up, its neck is facing ceiling, plus I can see this part of the bottle where a sticker is. If I move around my camera, the bottle should be "rotating" with it, too, so that I always see the said sticker and neck of that bottle is always facing ceiling.
Now, this could be easily achieved with just parenting bottle to camera, but there's another catch - I want to allow this bottle to bump onto things. When it hits something, it should rotate a bit, so that player sees very well it bumped onto something. But the bottle should always try to return to its original "direction" - namely, it should always try and achieve such rotation that player would again see its sticker, with neck of the bottle facing ceiling.
I'm at a loss how to do that. I tried setting rigidbody's angular velocity in different ways, tried MoveRotation(), but nothing seems to work. Could anyone help me here?
EDIT: This is what I've got for moving the held object (it's in FixedUpdate()):
Ray playerAim = player.PlayerCam.ScreenPointToRay(new Vector3(Screen.width / 2.0f, Screen.height / 2.0f));
Vector3 nextPos = player.PlayerCam.transform.position + playerAim.direction * player.GrabbedObjectDistance;
Vector3 currentPos = transform.position;
rigidbody.velocity = (nextPos - currentPos) * moveSensitivity * Time.fixedDeltaTime;
Your answer
Follow this Question
Related Questions
Physics gun like in Garry's Mod? 3 Answers
Pick Up Rigid Body 0 Answers
[SOLVED] Picking Up/Holding Objects Portal Style 2 Answers
Unassigned Reference Exception error? 4 Answers