Search Unity

2D Spaceship banking & thruster / laser effects

Discussion in 'Animation' started by asnowcappedromance, May 17, 2021.

  1. asnowcappedromance

    asnowcappedromance

    Joined:
    May 1, 2021
    Posts:
    19
    Hi guys,

    I'm building a 2D top-down space shooter as a practice in Unity. Using the 'Animation' panel, I created 3 animation states (idle, bank left, bank right). The banking states consist of 4 keyframes of different sprites to get smooth transitions between the states.
    Now the center of my spaceship is able to shoot a laser towards its enemies, and the thruster engines are supposed to emit flames. The problem I'm having is that when my spaceship is banking, the width of the sprite is being reduced due to the perspective change, resulting in the emission points for the laser/thrusters being offset from their actual position on the spaceship.
    I added a JPG/quick depiction of my problem, note that the thruster flames are being out of place when the banking animation happens.

    I could potentially solve this by adding children (empty gameobjects with transform components) to my spaceship gameobject, nudging each transform to fit a sprite keyframe of the banking animation and then switch between the emission points to instantiate a prefab.
    Is there any way in C# to do this, access animation states and which sprite we're currently displaying?

    Or does anybody have a better solution? I'm quite new to animation stuff in Unity.

    Thanks a lot,
    Cheers,

    Manu
     

    Attached Files:

  2. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
  3. asnowcappedromance

    asnowcappedromance

    Joined:
    May 1, 2021
    Posts:
    19
    Hi Brandy,

    I figured that one out, yes. As long as the game objects / transformations from which your emitting your laser/thrusters from are children of the main player game object, you can click on "Add Property" in the Animation window and then add new keyframes that are then being controlled by the same banking behavior animation.

    Cheers,
    M
     
    BrandyStarbrite likes this.