Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Rotate fireball in direction of flight

Discussion in 'Scripting' started by getmyisland_dev, Jul 24, 2022.

  1. getmyisland_dev

    getmyisland_dev

    Joined:
    Dec 22, 2020
    Posts:
    100
    I want to rotate my 2D fireball in the direction of his flight.

    Code (CSharp):
    1. // Shoot fireball in direction of player
    2. targetDirection = ((_targetTransform.position - transform.position)).normalized;
    This is how I calculate the direction of the fireball. And it works perfectly fine and now I need to rotate the fireball in the direction of the flight.

    I tried:
    Code (CSharp):
    1. // Rotates fireball in direction of player
    2.             Quaternion rotation = Quaternion.LookRotation(_targetDirection, Vector3.up);
    3.             rotation = new Quaternion(0, 0, rotation.y, 0);
    4.             this.transform.rotation = rotation;
    Since this is a 2D game I don't want any rotation on the x and y axis, only on the z axis.

    Can someone tell me how I can rotate my fireball in the direction of the player. If you need more information I'm happy to help. Thanks in advance.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,533
  3. getmyisland_dev

    getmyisland_dev

    Joined:
    Dec 22, 2020
    Posts:
    100
    MelvMay likes this.