0
votes

I'm looking for solution to smooth transform position of my object.

To moving to new position I'm using that code

transform.position += Vector3.left * Time.deltaTime * 100f;

The effect of moving is to fast, so I want to make it more smooth. There is any option to change this code for better effect? Like the small bricks in this video when ball destroy big brick

https://youtu.be/mqj7eYna3Ds

4

4 Answers

0
votes

You can also use this:

transform.Translate(Vector3.left * Time.deltaTime * 100f);

This should make it a bit smoother. Just remember if you would ad a velocity to the object, Transform.Translate wil not work nice! if you want more float like movement you can give a Addforce to the attached rigidbody.

rigidbody.AddForce(transform.left * 10, Forcemode.Impulse);

Note: If you use Translate there wil not be any acceleration!

0
votes

Rigidbody.AddExplosionForce may solve your problem but you cannot put the collision point as the origin. you may have to move your origin of an explosion a little bit below than the collision point. Let me know if it solves the issue.

https://docs.unity3d.com/ScriptReference/Rigidbody.AddExplosionForce.html

0
votes

Using AddForce or manipulating the velocity variable on the Rigidbody is better if you want smooth movement.

However, if your object doesn't have a rigidbody, then you can just use the functions provided with the Transform class (e.g: Rotate(), Translate(), SetPositionAndRotation())

0
votes

You can use this block of code to smooth out the movement of the player

           public Transform player;
           public Vector3 targetPosition;
           public float smoothFactor = 2;
           void Update()
           {
                 player.transform.position = Vector3.Lerp(player.transform.position, targetPosition, Time.deltaTime * smoothFactor);
           }