Move rigidbody towards position with velocity property
So im trying to pick up objects, but the problem is that when im holding it (by setting object position) it can go through walls. So i instead tried using rigidbody and moving it. So i have a invisable object infront of my camera and i need the pickupObject to move towards it with rigidbody.velocity, and there by if something is in the way it will stop but then when free, move towards the invisable object again. It sounds simple but im not really making any progress. Any help is welcome Thanks
Hi @fluxhackspro - I'm not quite getting your explanation, so I can't be sure what your problem actually is. You don't explain your object hierarchy, and what you are doing exactly.
However, I 'd first try using Rigidbody's $$anonymous$$ovePosition, $$anonymous$$oveRotation, AddForce and AddTorque -These can be used to move rb using physics system. Setting transform position (for example) or such will make object (and it's rb) to teleport in physics system's eyes.
See: https://docs.unity3d.com/ScriptReference/Rigidbody.$$anonymous$$ovePosition.html
Im sending a raycast from my camera and when i rightclick and it hit the layer "pickupAble" the hit object position is set to a positiion infront of the camera and follows it around (its picked up). But the problem is that im setting the objects position and because of that the object can go through walls. Im looking for a solution where the object moves more like in half life 2. if an object gets in the way the picked up object will collide with it. Tell me if you want my whole script, but here is the part that im talking about:
pickUpObject.transform.eulerAngles = new Vector3(pickUpObject.transform.eulerAngles.x, Camera.main.transform.eulerAngles.y, pickUpObject.transform.eulerAngles.z);
pickUpObject.transform.position = Vector3.$$anonymous$$oveTowards(pickUpObject.transform.position, pickUpPos.transform.position, 2);
Your answer
Follow this Question
Related Questions
Objects slowly move by their own? 1 Answer
How to make rigidbody character jump to lower ground? 0 Answers
How can I get a rigid body object to face in the direction my joystick is pointing smoothly? 0 Answers
Ball Rolling is not working 0 Answers
Anyway to count the number of joints a rigid body is involved in? 0 Answers