I’m currently working on a game project where I have a physics-based hand that moves towards a traced position using the following line of code in a FixedUpdate method:
rigidbody.velocity = (_followtarget.position - transform.position) / Time.deltaTime;
However, I’ve encountered an issue that I’m struggling to resolve. Whenever the hand comes into contact with the player’s body, the body is also being pushed and moved. I want the hand to interact with the body without affecting its movement.
I’ve tried a few approaches, but so far, I haven’t been able to achieve the desired outcome. I would greatly appreciate any suggestions or advice on how to tackle this problem effectively.
Thank you in advance for your help and insights. I’m looking forward to hearing your suggestions
Generally, don’t use the physics engine unless you really, really have to. When you use it, you will constantly be fighting it like this, where its idea of what should happen differs from your idea of what should happen.
When you must use it, make things kinematic as much as possible. Kinematic rigidbodies move only under code control; the physics engine will leave them alone (but they can still affect other physics objects).
In this case, the body is being pushed and moved because it is a non-kinematic rigidbody, and you’ve pushed another rigidbody into it. Rigidbodies are not allowed to intersect; the whole physic system’s basic job is to prevent their intersection by making things move. So. If you don’t want the body to move, then what do you want to happen? What does “interact with the body” mean to you? Figure that out, remove the rigidbodies or make them kinematic, and then write code to do whatever that is.
I understand your recommendation to avoid using the physics engine unless necessary. However, in my case, I want to maintain the overall physics simulation while ensuring that the hand remains still when it touches the body.
Making objects kinematic would remove their interaction with other physics objects.
If you have any suggestions on how to achieve this goal without making everything kinematic, I would appreciate your insights. Thank you!