Search Unity

Question Am i dumb or just not seeing something?

Discussion in 'Physics' started by WhitlockDEV, Nov 29, 2023.

  1. WhitlockDEV

    WhitlockDEV

    Joined:
    Nov 11, 2023
    Posts:
    9
    I have an "enemy" that when im in range, it chases me then attacks me, by shooting projectiles towards me, or atleast its supposed to.

    Here is a streamable link for the video showing what currently happens:


    Here is the function inside the enemies shooting script.
    upload_2023-11-29_23-21-26.png


    ive been at this for like 2 days now, i cant figure out what im doing wrong. The projectile's rotation is set to 0 in the prefab thing, ive tried pretty much everything i can think of.
     
  2. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    987
    YOU BLIND IDIOT!!

    just kidding!

    You're not dumb. Unity is very complicated and quirky and you'll still do silly things even when you've been using it for years.

    The issue is that you're spawning a rigidbody inside another object and it's messing with the AddForce direction.

    Instead do this:
    Code (CSharp):
    1. Rigidbody rb=Instantiate(projectile,transform.position+transform.forward,Quaternion.identity).GetComponent<Rigidbody>();
     
  3. WhitlockDEV

    WhitlockDEV

    Joined:
    Nov 11, 2023
    Posts:
    9
    Thanks bud, it worked like a dream!!