Limit the distance that gameobject can travel
I made a script that move an object by touch input (and it works fine), but the problem is that if I move the finger too fast, the object miss collisions with other objects (if I move the finger slower the object doesnt miss the collisions). so now I try to do in Update() that if the object moved more than max distance , he will move max distance in the same direction. (For example: last position is (0,0) , current position is (2,0), if the distance is greater than 1, current position will be (1,0). But I dont know how to do it, please help.
Answer by Map-Builder · Jul 30, 2017 at 09:29 PM
Best way is to raycast
Raycast from position recorded the frame before to new position (in layer that does not contain the object itself or it will collide). If the raycast encounters a collision then replace the object at the hit.point of the collision.
Note : may be replace away from this point if you're using non convex colliders (convex tends to push they object outside so it's ok, but mesh colliders may not)
there's an option within the rigidbody variable about making the detection "continous dynamic" but do not expect to much from it. But it may work
Your answer
Follow this Question
Related Questions
Get distance of one axis between two objects 0 Answers
Dot Product not equals 1 0 Answers
Spawned objects won't move in correct direction. 0 Answers
Position of empty game objects 1 Answer
What is Screen-Space Error 0 Answers