- Home /
How to make the bullet shoot
Already tried all methods available , but they all shoot in the same direction . I am a beginner but I need to make the shoot as fast as possible . In the script I usually intancio , however , is to move when it moves only in one direction , even when my player is aiming for the side or back .
Ou a bala simplesmente nen anda, fica no mesmo lugar até sumir, os dois metodos eu obtive apenas a instanciação e que a bala aponte para a posição que foi mirado
Shooting/InstantiateCode
function Update () {
if (Input.GetKeyDown("space")){
Tiro();
transform.position += Vector3.forward * speed * Time.deltaTime;
}
}
function Tiro(){
Instantiate(PTiro,transform.position,transform.rotation);
}
Please can someone tell me why I just can not I ?
Answer by gribbly · Nov 08, 2014 at 08:56 PM
The problem is here:
Instantiate(PTiro,transform.position,transform.rotation);
Instead of 'transform.rotation', you need to supply a rotation that points in the direction you want. Assuming transform.rotation isn't changing elsewhere in your code, it will always point in the same direction, so your bullets will always go in the same direction.
Try something like:
public GameObject enemy; //set this to your target
function Tiro(){
transform.LookAt(enemy);
Instantiate(PTiro,transform.position,transform.rotation);
}
...and see if that gets you closer to what you want.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Limiting Player Movement in 2D game? 0 Answers
top down 3d camera rotation question 2 Answers
How to make basic AI in a 2d game? 4 Answers
touch position to world position 2D 2 Answers