x


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.

more ▼

asked Nov 24 '10 at 03:36 PM

Rafael gravatar image

Rafael
3 5 5 7

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Nov 24 '10 at 03:47 PM

oliver-jones gravatar image

oliver-jones
2.5k 205 225 253

Its a Side Scrolling game. That would not work. thanks

Nov 24 '10 at 04:03 PM Rafael

Oh sorry - I didn't read your question properly, I was in a rush

Nov 24 '10 at 05:37 PM oliver-jones
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Nov 24 '10 at 04:24 PM

leith gravatar image

leith
23 1 1 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x982
x446
x316
x103

asked: Nov 24 '10 at 03:36 PM

Seen: 2047 times

Last Updated: Nov 24 '10 at 03:36 PM