Need some help with Object movement on Button press !!.

Need some help implementing movement to a 2d object with ui button events. I have a simple paddle and i want to move it with the help of 2 ui on screen button on which i’ve used event trigger functions referencing to the paddle script , but i’m missing something stuck on it for a while a little help would be appreciated.
this is what i did

public void MovePaddleRight()
    {
        transform.position = (rigidbody2D.position + new Vector2(10, 0) * Time.deltaTime);
    }

    public void MovePaddleLeft()
    {
        transform.position = (rigidbody2D.position + new Vector2(-10, 0) * Time.deltaTime);
    }

the paddle just snaps to the position without and smooth motion. basically all i want is to implement
Onbuttondown move to the relative position and onbuttonup stop moving.and vice versa.
Please can someone help me out with this i’m kinda stuck on it for a while…thanks in advance.:slight_smile:

With moving rigidbodies you want to add force or set velocity (because you are dealing with physics) - setting the transform position will just tell a thing where to be in the world without any consideration for physics, so it will ignore collisions.

That said, if you want to get an object to move smoothly from point A to point B look at Unity - Scripting API: Vector3.Lerp. The reason your code is making it snap to a new position is because it calls for a change of position in only 1 frame (assuming your method is called OnButtonDown/Up). The stuff in that link will explain how smooth movements via script work.

Alternatively you can animate the paddles which sounds like the simplest solution based on the very limited knowledge I have of your project :stuck_out_tongue: - it’s very quick and easy with Unity’s built in animation. This video alone will tell you everything you need to know about setting up animation on an object Basics of Animating - Unity Learn. You can then call animations from your methods (Unity’s website and Youtube have a lot of tutorials on this - if you want to go that route and want more info let me know!)