- Home /
physics question my object setup failing collision
How to slow down a position transform that is being manipulated by hslider GUI input????
My problem is that I'm adjusting a 3D in game object's position transform based on a GUI slider value. It works like a charm most of the time. The object being adjusted (using its position adjusted from hslider values) is a simple box with box collider and no rigid body element. This box moves rigid bodies in the scene.
//this is used to transform the position
transform.localPosition = Vector3(positionX,positionY,limitControl.hSliderValue);
Everything is fine if I adjust the slider value slowly. If I move it quickly, it goes right through the rigid bodies it is supposed to manipulate.
Why not use torque or addforce to adjust the box? Because I need it to move within a specific range of transform coordinates. I really just need to slow down the movement of the "transform.localPosition
" or find a more reliable way to detect collisions. I've tried a variety colliders on the box being transformed with hslider and elements in the scnee (rigid bodies) that is pushes. I've also tried a wide variety of editor settings for rigid bodies within the scene.
Answer by Cyb3rManiak · Oct 18, 2010 at 03:29 PM
You can try and use Mathf.SmoothDamp() or in case you're using Unity3D 3.x - Vector3.SmoothDamp(). This will try and move a float (or a Vector3) to a certain value with ease-in and ease-out to get a smooth movement. There's even an optional parameter that will let you set the maximum speed the value can change, so you can cap it.
And BTW - another solution to your problem is to increase the physics engine's solver iteration count in the physics settings. It might catch collisions on higher speeds as well if your computer is fast enough to handle it (Since it will make physics run more frequently - and in turn will cause "some" performance hit).
Answer by vertex · Oct 21, 2010 at 08:45 PM
Thank you. Mathf.SmoothDamp() Did it in the end. The movement is now smooth and collisions have time to do their business.
Answer by Bravini · Oct 18, 2010 at 03:26 PM
use transform.Translate / update the movement using Time.Deltatime, this way it will move incrementally and more smoothly.
I started with translate and it was smooth but had issues stopping at a specific point of the slider.
Your answer
Follow this Question
Related Questions
make player move in direction it's facing 2 Answers
What is the reasoning of multiplying by Time.deltaTime 1 Answer
does not work check if dead 1 Answer
Help around an approach to a "Virtual Motion Table" in Unity 0 Answers
Camera movement 1 Answer