Enemy shoots diagonal (sidescroller)

Hey all,

clever as I am, I try to make the game a sidescroller, just because I can…can’t haha.

Anyway, shooting works fine BUT the lasers are first going diagonal and then in a straight line. I have attached a picture that shows it. After roughly at that point, laser flies in a line as it should. All Drags and mass is set to 0…any ideas?

Cheers

Hi Johnny,

What velocity do you give the lasers? Have you tried to disable the gravity in the Physics settings?

Hi Nina,

project settings physics (both physics and physics 2D), gravity x and y are set to “0”

interesting is that this is only for the ENEMY lasers, not for the player one, that is fine. I have checked the code and also just copied it for testing from the lecture, so there is not typo here I think

private void Fire()
{
GameObject laser = Instantiate(
projectile,
transform.position,
Quaternion.identity
) as GameObject;
laser.GetComponent().velocity = new Vector2(-projectileSpeed, 0);
AudioSource.PlayClipAtPoint(shootSound, Camera.main.transform.position, shootSoundVolume);
}

It’s really funky as like said, it first goes diagonal but then it ends up flying in a line. I also thought it’s just a visual thing because the ship is so fast higher then the laser so it looks like it’s diagonal, but I set the speed of the projectile really slow for testing and still, it falls like a bomb before moving forward.

getting crazy as I finished the the rest of the laser defender course but can’t close it now :smiley:

How is this possible if you set the gravity to 0?

haha no idea :slight_smile: ?

this is what it looks like

and this is the laser (I also froze Y but nah)

when the enemy flys UP, the laser falls down and vice versa

Could you set the Mass to 0 in the second screenshot?

Also try to set the Body Type to “Kinematic”. The Body Type of the Player must be set to “Dynamic”.

Then run the game. If the laser rotates again, select it and check its Transform. If the rotation is not (0, 0, 0), the issue might be Quaterion.identity.

thanks nina, I will try asap!

How are you getting on with this, @Johnny_Beatmann?

Hi Nina, I moved on to other grounds and will spam in another course very soon :wink:

Thanks for letting me know. :slight_smile:

I’m closing this thread now. If you still need it, message one of the moderators and ask them to re-open the thread for you. Alternatively, create a new thread.

Privacy & Terms