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.

Dark GDK / Shooting the angle the player is facing

Author
Message
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 30th Nov 2008 19:58
I have got guns to fire, but only on one axis at a time (X or Z), how would I be able to make it shoot which way the character is facing? I know I would use trig, but I can't work it out. Help.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 30th Nov 2008 20:15
How are you doing the shooting? Raytracing or an actual bullet? For a bullet, just set the bullets rotation to the same as the player's, then move that forwards.
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 30th Nov 2008 20:16
Im raytracing. Should I use bullets?
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 30th Nov 2008 21:07
no.
Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 30th Nov 2008 21:44 Edited at: 30th Nov 2008 22:01
To move an object in the direction of an angle, there are 2 equations for 2d and 3 for 3d (one for each axis).

Bear in mind that the code below assumes all the angles you have start at 12 o'clock and increase clockwise.

For 2D, the equations look like this


For 3D, you have to modify the X and Z movements because they will differ depending on how far up or down the direction is. In a 3D case, two angles will do; one for looking up and down (AngleX, a rotation on the X axis) and one for looking side to side (AngleY, rotation on the Y axis). Ultimately, your final direction is calculated by applying the X rotation first (rotating an axis-aligned object from a side perspective) and then the Y rotation (rotating what we have now from bird's eye veiw), and finally the Z rotation (rotating what we have now from directly behind; screws things up, so leave it 0).

Here are the equations:


To remember which trigonometric function does what, here's a simple demo program that shows what the sine and cosine are of a DGDK angle.




Remember those old guys? They made epic renders, I think one of them was called DaVinci, and all they used was MS Paint. Sometimes it's just skill....
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 30th Nov 2008 22:50 Edited at: 2nd Dec 2008 17:00
That is very useful!
when I add this, all it does is add a collision above me??

prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 2nd Dec 2008 17:00
bump

Login to post a reply

Server time is: 2024-11-25 07:46:29
Your offset time is: 2024-11-25 07:46:29