[SOLVED] Trouble with Bomb Script on Player Move

Updated on December 14, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on December 12, 2017

I have tried a lot of different options to try and get my bomb throw to work. I mean it does work but on player move my bomb throws incorrectly. I have gone through quite a bit to figure it out such as using velocity rather than Addforce but nothing seems to help. So I was hoping maybe someone had a suggestion. So the problem just to clarify is that if I move backward the bomb throws forward and if I move forward the bombs throw backwards. The rotation seems correct. This is in c# btw. Thank you for any reply.








//Bomb script:
void BombThrow() {
    GameObject bomb = Instantiate(ExplosiveDevice, transform.position, transform.rotation);
    Rigidbody rb = bomb.GetComponent();
    rb.AddForce(bomb.transform.forward * bombLaunchSpeed);
//Movement Script (This is a seperate Script from my bomb script):
public float movementSpeed = 8.0f;
 public float rotateSpeed = 5.0f;
 void Update()
    float x = Input.GetAxis("Horizontal") * Time.deltaTime * rotateSpeed;
    float z = Input.GetAxis("Vertical") * Time.deltaTime * movementSpeed;
    transform.Rotate(0, x, 0);
    transform.Translate(0, 0, z);








Here is a video of my problem:







  • Liked by
0 on December 13, 2017

maybe this could help:



  • Liked by
0 on December 14, 2017

Not at all actually that is where I got the start up from. Lol I love Brackeys.

But I fixed it anyway so here is the line I added to fix it:

rb.velocity = launchPosition.TransformDirection(-Vector3.forward * bombLaunchSpeed);

Btw this depends on your situation but for mine it worked perfect. You might need to change the direction it launches depending on how yours is rotated.

  • Liked by