How can I move a scene object A, that contains a Collider component as well as a RigidBody, in order that if such object A is blocked by another static object B, that also contains a Collider component, object A’s translation will be limited to object B’s bounds? All of this WITHOUT using a CharacterController or RigidBody.AddForce.
To be move specific: I am only interested in limiting specific movements. Gravity, rotation, slope limits, inertia, all of these can be disconsidered. I originally was working just by updating the object A transform’s position and manually checking the scene’s bounds (sometimes with the help of OnTriggerEnter, sometimes with a custom solution), but the workload has become overwhelming.
Any suggestions? Am I going at it the wrong way?
Thanks in advance.
I’m a bit confused by your question. The way I’ve interpreted what you’ve asked is “how can I preserve collision while not using a character controller or rigidbody forces?”.
If this is the case, all you need to do is update your object’s transform.position at runtime. As long as both objects have colliders and rigidbodies, physics will still act upon them and prevent them from occupying the same space.
So, for instance, let’s say object 1 is a sphere and object 2 is a wall (cube). You can give both objects a collider (sphere and box, respectively) and a rigidbody. You could choose to make your wall’s rigidbody kinematic, so as to freeze it in world space. Then you might choose to freeze your sphere’s rigidbody x, y, and z rotation (depending on the application).
Then, all you would need to do is update your sphere’s transform.position from code, and the colliders should work as expected when the sphere reaches the wall.
Hope this helps!