Smooth shooting in 2d orthographic camera

Hi,

I am new to Unity with developing 2D games. I am trying to shoot bullets in X and Y directions simultaneously. I am setting gravity to the bullet so that it comes down.

I am not able to have a smooth clean shoot possible. While reaching its(bullet) peak, it starts wobbling and while coming down it wobbles vigorously !

        float amountToMove = bulletSpeed * Time.deltaTime;
		
		//Move the bullet
		//transform.Translate(Vector3.up * amountToMove);//Working
		
		//Try to fire in a parabola
		float rightDir = (Vector3.right * amountToMove).x;
		float upDir = (Vector3.up * amountToMove).y;
		transform.Translate(rightDir, upDir, 0.0f);

I am using ‘Orthographic’ Projection.

I would like to have a clear parabola like motion without pauses/stoppages. Is there a way to do it ? I am referring to TheLorax’s 2D game shooter tutorial.

The problem is in your math. You are trying to create parabolic movement but both x and y axes are getting the same values. You want your x axis to have a constant speed and your y axis to lose height from gravity each frame.

alt text

I think you may have a different sort of bug in this code as well:

float rightDir = (Vector3.right * amountToMove).x; 
float upDir = (Vector3.up * amountToMove).y; 
transform.Translate(rightDir, upDir, 0.0f);

that’s the same as doing:

transform.Translate(amountToMove, amountToMove, 0.0f);

Personally I’d just add a rigid body to the bullet and use the add force function.

Look here.

var bulletForce : Vector3 = Vector3( 10, 10, 0 );

function Update()
{
    if( Input.GetButtonDown( "Fire1" ) )
    {
        rigidbody.AddForce( bulletForce );
    }
}

This script would need to be attached to the bullet and the bullet would need to also have a rigid body component as well. This wouldn’t be good if you were going to have lots of bullets in the scene but you should be able to get the idea.

edit: use real world sizes, makes things much easier, especially if you want to work out where the bullet lands…