DemoProductions / shmup

3 stars 2 forks source link

Rotate weapon prefabs #119

Closed flip40 closed 7 years ago

flip40 commented 7 years ago

Weapon prefab shoots up by default. Weapon should always face "forwards" relative to its parent (rotating the parent should keep the weapon firing where the parent is facing). Cases of weapons that shoot up, down, etc. should be handled by the various weapons classes we might add (i.e. subclasses) which will also face forward, but not fire the bullet forward.

ghost commented 7 years ago

When the Player had the blue square sprite I had the Player's transform set to something like (0, 0, 270). Can choose to always shoot from this direction, unless the player can change the direction they are facing. If that happens, then can add or subtract 270 to the Z axis of the Player's transform

Or a fix without code changes can be to rotate the sprite itself

flip40 commented 7 years ago

Rotating the sprite wont fix the issue... the issue is not with the player, it is with the weapon being rotated incorrectly. Rotation and positions are overridden when prefabs are instantiated (remember instantiation requires passing a v3 position and a quaternion rotation), so making rotation/position changes to prefabs will also not fix the issue.

Code fix is required because of this. One of these conditions is currently broken and we need all of them to be true:

There are some oddities on code, which unfortunately make it look a bit annoying (for example, if i recall correctly, if the bullet matches the weapon orientation, and uses tranform.forwards to determine which way it moves, it doesn't go where you might expect... I believe it used transform.up. You could rotate the bullet sprite when instantiated so that you could use transform.forward, however then we have the confusion on why we have to rotate all our bullets by +-90 degrees....)

flip40 commented 7 years ago

Ah, I think I may have misunderstood your earlier comment. Perhaps the player is now not rotated when we may have initially had is spawn in a rotated fashion, like you said.