Bullet shooting not working
I'm trying to make a mechanic where if the player runs into a certain gameobject, they can shoot fireballs. That part works alright, but when the object is instantiated, it doesn't shoot forward like it should. It just falls to the ground. What am I doing wrong? I think the problem is within the Update function. #pragma strict var fireball : Rigidbody; var ShootFireballs = false; public var forward: Vector3; function Start () { } function OnTriggerEnter (Other : Collider){ if(Other.gameObject.tag == "fireflower"){ ShootFireballs = true; } if(Other.gameObject.tag == "Enemies"){ ShootFireballs = false; } } function Update () { if (ShootFireballs == true) { if(Input.GetKeyDown(KeyCode.E)) Instantiate(fireball, transform.position, Quaternion.identity); fireball.position = transform.position; fireball.rotation = transform.rotation; fireball.velocity = transform.TransformDirection(new Vector3(0,0,20)); } }
Your answer
Follow this Question
Related Questions
Rigidbody.velocity Movement code produce wildly different gravity interactions 0 Answers
rigidbody.MovePosition to rigidbody.velocity 0 Answers
Rigidbody velocity forward is Camera forward 1 Answer
Only limit player input and not external forces (Rigidbody 3D) 1 Answer
Check/Change velocity of an object 0 Answers