- Home /
 
               Question by 
               Ruchaice · Sep 30, 2021 at 08:20 AM · 
                3dshootingmouseposition  
              
 
              How to make player's projectiles move to the mouse click position in a 3D top down shooter game?
I'm currently making a 3D top down shooting game, and I want the player's projectiles to go to the position of mouse click. But right now I cannot find a way to make the bullets go the mouse position.
Here is my code so far.
public class shooting : MonoBehaviour { public GameObject projectile; public float shootingForce;
 // Start is called before the first frame update
 void Start()
 {
     
 }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Mouse0))
     {
         GameObject shot = GameObject.Instantiate(projectile, transform.position, transform.rotation);
         shot.GetComponent<Rigidbody>().AddForce(transform.forward * shootingForce);
     }
 }
}
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
3D top down shooter mouse follow inaccurate. 0 Answers
left and right shooting 1 Answer
Make an object move towards the mouse and then keep going 0 Answers
how to add firerate to enemies shooting script 0 Answers
Getting 2D projectiles that fire in the direction of the mouse position to work in unity 5? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                