Hi all, im quite new to Unity and am working on a simple shooter on rails, however I am having trouble getting the projectiles when you shott to head out in the right direction.
I have made a gun object that is attatched to the camera, I need the gun object to shoot out wherever the player clicks, im not sure if this is the best way to do it or if I should maybe use raycasting instead?.
Here is the code I have so far, any help would be greatly appreciated.
Your first problem is in the fact that you are just using the mouse coordinates - they aren't in work space so that will give you a problem right there :)
You want to use:
This gives you a ray, now you need to decide how far from the camera the target is and do this
answered May 26 '12 at 04:09 PM
How fast is your projectile ? Bullet, arrow, bubble ? If the projectile is too fast to even be seen, don't bother with a GameObject at all, use a raycast and something for the impact. For an arrow-like speed, it becomes relevant to have a body.
answered May 26 '12 at 03:15 PM