- Home /
Managing collision with transform movement
Hello all, We've recently had an intern that has developed a script to simulate diving, it's very complicated and well done, and now it's my job to implement this script. The only problem is that this script does not use rigidbody or characterController, it changes directly the transform position. This is a problem when it comes to managing collision, as for the moment, we can pass straight through the sea floor and rocks etc... The script has been worked on for a long time, and I would much rather not have to redo/change it allot to use rigidbody or character controller. Does anyone have any suggestions and the best way to manage/mimic collisions without rigidbody or charactercontroller?
Thanks in advance.
you can write your own collision system then and thats pretty complicated work. or you work with distance, directions and all.
It'll probably be easier to redo the script using a rigidbody than write your own collider.
Hi, you can ask Unity if an object is colliding another with the Physics.CapsuleCast or CheckSphere and then react to it yourself (as well as the RayCast functions).
Something else that may be more simple is use a rigidbody but manage it's dynamic yourself and let Unity handle collisions and collisions reactions. To do that, set the gravity to 0 (I guess you handle it yourself). In FixedUpdate, do your computations to get the new position of the object according to your dynamics. Compute Vector3 deltaPosition = newPosition - transform.position. Then, assign the rigidbody.velocity to deltaPosition * 1.0f/Time.FixedDeltatime. Unity will compute the new position using this velocity and it should end up positioning the rigidbody exactly where you computed the new position. If there is an object blocking the way, your object will react to the collision, then ending not exactly where you wanted it but well, there was a collision so... ;-)
Thank you for your suggestion, I've attempted using rigid body.position and rotation ins$$anonymous$$d of transform.position and rotation, it does stop when colliding but with other strange results, if i keep trying to go through that wall i will pass and then all hell will break loose with vibration and jumping. and I did try the newPosition - transform position and setting the velocity, only the object doesn't move at all, I must be taking the transform in the wrong place or something silly, so will retry that! I think using recasts could be a good option, and I'm going to look into Physics.CapsuleCast and CheckSphere. Thank you @dns When/if I find a way, I will post how I got there
Your answer
![](https://koobas.hobune.stream/wayback/20220611232508im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
the player don't move with the transporter,,The occurrence of the player from the carrier 1 Answer
OnCollisionEnter doesn't work if enemies and allies have rigidbody ? 1 Answer
Rigidbody: how to get collisions for the current frame ? 0 Answers
how to make an Explosive rigidbody trigger by another collision box 0 Answers
Car dynamics? 0 Answers