# Movement nudge instead of constant

I am making a small game where the player is constantly moving upwards, and I am having slight problems with the movement to the sides. The script located under works quite perfectly in itself, but my problem is that I want the balloon-player to nudge in a direction, rather than go at a constant speed. Kinda like a small punch to the side of the balloon.

How could I easily implement this? GetMouseButton or GetMouseButtonDown? Thanks in advance. :)

    void Update () {

transform.Translate(Vector3.up * Time.deltaTime, Space.World);

if(Input.GetMouseButton(0))
transform.Translate(Vector3.left * Time.deltaTime, Space.World);

if(Input.GetMouseButton(1))
transform.Translate(Vector3.right * Time.deltaTime, Space.World);

}

• As in you want some push when the button is clicked once? Then you want it to slow down over time?
– Ben
Commented Nov 10, 2014 at 11:35
• Yes. This will be for my android tablet, and I want simple taps on the sides to nudge the balloon in that direction. so a small acceleration as well. :) Commented Nov 10, 2014 at 11:38
• You should use Lerp for this Commented Nov 10, 2014 at 12:46
• Sounds like you just need to apply some force. Commented Nov 10, 2014 at 14:14
• For what I see you are not using physics, are you? Without using physics you need a couple of tricks to reach your final effect: 1) reproduce a little tilting/rotating animation on your baloon sprite (rotate around z-axis) and come back to initial rotation. 2) use Vector3.Lerp to add an extra slide-movement component to your translation vector and apply over a time-window. If you need more code just ask.
– Erik
Commented Nov 10, 2014 at 14:54

This looks like it would be something the physics system could fairly easily handle. I'd add a Rigidbody2D and then you can manipulate the balloon via the AddForce function. Note that in order to make the balloon "rise" you can get rid of your translate and instead set GravityScale to something like -0.5 and it will "fall" but up.

So I'd do something like this:

void Update ()
{
if(Input.GetMouseButtonDown(0))
{
}
else if(Input.GetMouseButtonDown(1))
{

• You have to turn OFF IsKinematic and you have to make sure you're not trying to manually change the object's position yourself. Commented Nov 10, 2014 at 19:37