Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Look rotation viewing vector is zero dismiss error? the problem is that only works like this.

Discussion in '2D' started by andresbvalenzuela, Oct 21, 2020.

  1. andresbvalenzuela

    andresbvalenzuela

    Joined:
    May 4, 2018
    Posts:
    3
    Hi, i have a problem with my script, the thing is i want a bullet to spawn and set it's direction to the player, the problem is that i'm new to using corgi engine, and tried to use set direction, and tried other vector3 general lines like forward up right, and didn't work, only with zero, the thing is that since it is working, i just want the editor to just not spam the debug that look rotation viewing vector is zero, because it works, and it just messes with my personal debugging.
    i'll post the code here.

    Code (CSharp):
    1. void Shoot()
    2.     {
    3.         if(canShoot == true)
    4.         {
    5.             GameObject Bullet = Instantiate(Projectiles,gameObject.transform.position,Quaternion.identity);
    6.             Bullet.GetComponent<Projectile>().SetOwner(gameObject);
    7.             Vector3 dir = (Bullet.transform.position-Palette.position).normalized;
    8.             Bullet.GetComponent<Projectile>().SetDirection(-dir,Quaternion.LookRotation(Vector3.zero,dir));
    9.             float angle = Mathf.Atan2(-dir.y,-dir.x) * Mathf.Rad2Deg;
    10.             Bullet.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle + offset));
    11.             Debug.Log("Shoot");
    12.         }
    13.     }
    so even if i need to go to metadata to make the error go away i could do it no problem, i just want to know where to go and change that if possible, thanks.

    EDIT: the set direction line just sets the direction of the physics applied to the projectile, that's why i change the rotation afterwards.

    EDIT2: Fixed it, just by making the changing the lookrotation with another Quaternion.Euler like in the line that i use to set rotation, and it works no problem without a debug log.
     
    Last edited: Oct 21, 2020