- Home /
Specific weird problem with bullets in 2D game?
It's a 2D platformer game where each time the enemy shoots, it finds the player's position and makes the bullet go in that direction. The first enemy that already exists when the scene starts shoot bullets correctly as you can see in this screenshot: https://prnt.sc/ijb54u . But a problem happens with all the new enemies that are instantiated by an "enemymanager" object. The problem is that when the player is above or under the enemy, the enemy bullet gets thinner as you can see in this screenshot: https://prnt.sc/ijb6i0 .
I already made prefabs for all these objects and assigned them correctly to their specific public variables. Also, I tried rotating and scaling in the bullet's script after 0.1 second and it didn't work. This is the code that makes the enemy shoot:
creatingbullet = Instantiate(enemyA2Bullet, transform.position, Quaternion.identity);
creatingbullet.transform.LookAt(targetisplayer.position);
creatingbullet.transform.Rotate(new Vector3(0, -90, 0), Space.Self);
When I tried removing and changing the last line of this code, the bullet worked even weirder.
Hope someone can help me, thank you.
Answer by Kishotta · Feb 24, 2018 at 11:45 PM
The issue you're having is that transform.LookAt
doesn't concern itself with whether you are in 2D or 3D. Your sprite appears thinner because it is rotated in 3D. However, you can specify the worldUp
Vector3, which should give you the desired rotations:
creatingbullet.transform.LookAt(targetisplayer.position, Vector3.back /* towards the camera */);
Your answer
![](https://koobas.hobune.stream/wayback/20220612153350im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to detect if player had switched direction of movement? 0 Answers
(2d in 3d) Movement relative to camera using JS 0 Answers
Help rotating gun towards mouse position (with flipping) 1 Answer
Rotating A Character 180 Degress 1 Answer
Restrict a player's movement to a path for a 2.5D game that has curved paths 6 Answers