- Home /
Using a real game gun
Hi
I want to make a target game, similar to Duck Hunt but even more simple. Just a grid of squares on the screen, if I hit one with the right color then it would count as a hit. Is there a gun I can buy and program for Unity that would detect the colours I shoot at, or is there another way to do this?
What you want my friend is Raycast, You can use this to detect what ever has been hit, even a materials color.
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
I would assume that any gun controller would come with drivers that would control the input and the keys could be mapped to any existing ones. You may have to get yourself a cheap USB one and have a play around.
Answer by ZorNiFieD · Dec 12, 2012 at 02:38 AM
http://wiki.unity3d.com/index.php?title=UniWii
Everyone has access to a wii remote, so why not just use one of those?
How would this work though. What sensors on the remote would detect if you are actually pointing on the target?
I wrote a really long response, then lost it on submit. =/
Think of the wiimote as just like any other input in unity, cursor, keyboard or otherwise. The wiimote would use the following properties to obtain current position:
wiimote_getAccX(int which) wiimote_getAccY(int which) wiimote_getAccZ(int which) Returns the raw values for Wiimote accelerometer for each axis. The return value is a byte, so the rotation values can be from 0 to 255.
You will need to use Raycasting to achieve what you want as john essy stated. I recommend going to youtube for that ins$$anonymous$$d of reading the documentation as there are literally thousands of tutorial videos on the subject matter. Here's a search that will start you in the right direction:
Your answer
Follow this Question
Related Questions
Bullets getting stuck in air 1 Answer
JavaScript - FireMode Toggle Help 1 Answer
Need help with gun script to reduce the gun's rate of fire 1 Answer
Gun movement 1 Answer
Problem with "if" statements 1 Answer