Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

3 Dimensional Chat / Mounting a gun to a camera

Author
Message
stevenup 7002
18
Years of Service
User Offline
Joined: 26th Feb 2006
Location: Ireland
Posted: 2nd Jul 2007 14:37


Anyway, I am looking for the X,Y and Z coordinates for mounting a gun to a camera in my game so that its there like a sprite but can be moved when needed (Shooting etc.). I'm really stuck on this and I would appreciate any help. Here is the loop code I'm currently using:



The problem with that is the gun moves when I turn. Any Ideas?

Thanks,
-Steven

Co-Founder, President, CEO and Head Programmer of Motron Software. http://www.motronsoftware.com
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Jul 2007 16:47
Well it can get real tricky, but that's why DBPro's is full of cheat ways to do this stuff. I don't suggest locking the gun to to camera, because then you loose your limb position stuff - which is the easiest way to track bullet positions and flares etc.

Anyhoo, if you position your gun exactly where your camera is, then rotate it to the same angles too:

Position object 1,camera position x(),camera position y(),camera position z()
Rotate object 1,camera angle x(),camera angle y(),camera angle z()

Now by simply moving your gun object forward, it'd be in front of the camera the whole time. The clever part is that you could move it forward 10 units, pitch it up 90 degrees and move it again then pitch it back down 90 degrees. By turning left and right, and pitching, you can position the gun wherever you want on the screen.

Takes time to get it right, but it's the best way to retain those limb positions.


Good guy, Good guy, Wan...
Reality Forgotten
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Wichita Falls TX
Posted: 2nd Jul 2007 17:39
Help me understand this,

You want to have the gun movements different from the camera movements/player movements? Sorta like BF2142 or BF2, correct?

Why not set the camera/player movements to W,A,S,D keys and then the gun movement based on the mouse position?

I tried this with a flight sim test of mine and was able to do it, but I got some strange camera rotations with the secondary object.

Here is the code I used for the mouse rotations.



The numbers have to be worked a bit more, I think you can get the jist of what It's doing..'er trying to do..


If you want the whole project to test out let me know, I use this program to look at my heightmaps before I save them as objects...

Cheers,
Dave


Login to post a reply

Server time is: 2024-11-26 06:45:54
Your offset time is: 2024-11-26 06:45:54