- Home /
Mouse Aim- Weapons
My class mates and I are making a 2.5D Side Scrolling game. We need the gun to follow with the mouse (Aim). I can't find a script to get this off the ground. If anyone knows how to do this or can teach me, it would be great thanks.
Answer by oliver-jones · Nov 24, 2010 at 03:47 PM
Im guessing you have a player controller in your scene, all you do is open up your Player Controller (using the arrows) and drag your weapon into the Main Camera so its a child -- this will allow your weapon to follow your camera. Which is what you want.
Oh sorry - I didn't read your question properly, I was in a rush
Answer by leith · Nov 24, 2010 at 04:24 PM
My initial thoughts focus around using a large hidden plane and the raycast functions of unity. Since your game is 2.5d, its a little difficult to know exactly how you want the aim to work. The ".5" could include concepts of appearing to aim off axis as an example. But since your camera is likely still a perspective based camera, you probably want a plane that constantly updates to the view frustrum at the appropriate "depth" of the character, and to then do raycasts from the screen space position of the mouse, into the scene from the camera. Collide against the plane. Once you have that intersection, a simple vector subtraction and normalization will give you a vector with which to point the gun in 3d.
Your answer
Follow this Question
Related Questions
2.5d game gun aim 1 Answer
my gun wont follow my mouse 0 Answers
Gun object following mouse. 2 Answers
Javascript Gun Firing Script Edit 1 Answer