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

Stopping bullets from being affected by the shooters speed

Discussion in 'Scripting' started by epochplus5, Apr 8, 2021.

  1. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    Aggggh i just cant remember,

    i have only noticed now that my bullet direction is slightly being influenced by the object thats shootings speed.
    How can i correct this?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    Gonna have to show us your shooting code for us to be able to help you.
     
    Joe-Censored likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    Usually you have to do something extra to make the player's speed affect bullets.

    The only other thing might be that if you are using physics, your player is physically bumping the bullet from behind, but that usually results in wildly ridiculous bullet deflection / speed change.
     
    Owen-Reynolds and Joe-Censored like this.
  4. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    sure! heres my laser method:

    Code (CSharp):
    1. public void FireLaser()
    2.     {   if (!hyperSpace && isAlive)
    3.         {
    4.             FindObjectOfType<AudioManager>().Play("PlayerLaserRed");
    5.             GameObject newLaserRed = Instantiate(laserRed, weaponSpawnPoint.transform.position, transform.rotation);
    6.             newLaserRed.GetComponent<Rigidbody2D>().AddRelativeForce(Vector2.up * laserRedSpeed);
    7.             Destroy(newLaserRed, 0.8F);
    8.         }
    9.     }
     
  5. Mikeramczyk1977

    Mikeramczyk1977

    Joined:
    Jul 12, 2020
    Posts:
    58
    If you are talking about the spawnpoint of the bullet appearing to shift slightly side to side and back and forth upon firing while moving, then the issue might actually be your player move script. I find that oftentimes this issue is actually caused by your player move script, rather than your bullet or gun script. Try using just the straight character controller and the locomotion system for player move, even if only for testing purposes, and then try to move back and forth and run while shooting.
     
    Joe-Censored likes this.
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'm wondering if he is seeing player movement happening after the bullet spawn. So the bullet spawns at the position the player was the previous frame.