- Home /
Firing projectile towards mouse position from player...
I have been trying, research, etc... and I came up with only JavaScript results, which do not suit me since I work with C#. So basically, what I require is, when the left mouse button is clicked, I need a projectile (prefab) to be instantiated from the player's position and to move towards the mouse cursor's position. Now obviously I need it not to follow the cursor, but to fly in a straight line at that position. I cannot yield any results with my incomplete code, so can someone assist me with this problem please?
so you need to convert mouse position to world position, instantiate projectile, then projectile.transform.lookat(mouseposition), and finally just let the projectile move forward with projectile.transform.translate
Should the projectile follow a trajectory parallel to the floor of your world, or should it try to hit the point in the ground that intersects with the user click? Based on this you will want to calculate the transform position and rotation of your projectile before putting it to advance.
I've slightly changed how I want it to be - what I now want is the player character to be rotated to always face the mouse cursor, whereas the projectile has no involvement whatsoever. How can I rotate the player to always face the mouse cursor?
It's a top-down game, if it helps.
following will cause the player to always look at mouse position
void Update () {
transform.LookAt(mouse position );
}
2D or 3D?
What is the orientation of your top down? That is, is the camera looking down the 'y' axis or did you construct your game so that the camera looks towards positive 'z'?
How is your model constructed? That is, is the 'forward' of the object facing positive 'z' when the rotation is (0,0,0)?
Orthographic or perspective camera?
If 3D with a perspective camera, at what distance from the camera do you want to define the mouse cursor?
Is the camera parallel to the plane of rotation or at an angle?
Your answer
Follow this Question
Related Questions
Fire missile to mouse click 1 Answer
Fire object towards mouse cursor 1 Answer
Firing towards mouse- aim in all directions? 1 Answer
Spawn Objects Where i click 2 Answers
click on screen to get the coordinate on the ground(x,z plane) 1 Answer