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.

Newcomers DBPro Corner / 3D Projectiles Question

Author
Message
Tony Martin
15
Years of Service
User Offline
Joined: 5th Jun 2009
Location:
Posted: 18th Jan 2010 05:34
I see lots of stuff about 2D projectiles and I'm pretty confortable with that.
But now I'm venturing into the 3rd dimension and can't wrap my head around how to deal with Z.

Say I've got a tank wit the turrent turned to some angle, it launches a projectile at 45 degrees. Computing X & Y components, no problem - Figuring out what direction in Z...ARG!!!

Can somebody please enlighten me?
Thanks!
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 18th Jan 2010 17:14 Edited at: 19th Jan 2010 20:13
Often, no projectile is used for a tank, but a calculation is made as to where it will hit and an explosion is placed there. If you want to use a projectile, I would set it to the same X, Y and Z angles of your turret (and obviously position it there) and then simply move it at a speed which lessens the further the projectile travels. I'm not 100% sure, and I don't have time to check it, but I think you can alter the X angle of the projectile slightly each time it is moved to give it downward movement as needed.

Click my sig to download TGC Heroes v0.94.

Tony Martin
15
Years of Service
User Offline
Joined: 5th Jun 2009
Location:
Posted: 20th Jan 2010 20:19
I'm sorry but I didn't understand how you figure out how to adjust the trajectory to account for the 3rd axis...

What I'd like to do is show the path a projectile would take through 3D space. I was just using the tank projectile situation because it was really the first thing that came to mind. Now that I think about it, a simple 3D "scorched Earth" clone would be a good applicaiton to learn the language with and try out some 3D Physics at the same time.

Thanks again!
Master Man Of Justice
16
Years of Service
User Offline
Joined: 13th Feb 2008
Location: Between Insanity and Intelligence
Posted: 21st Jan 2010 05:49 Edited at: 21st Jan 2010 18:09
Hey Tony, i wrote this code up in a few minutes, i actually learned a few things too, but im also stumped,
you have to hold the space bar to make the ball move, but i was wondering if anyone knows how to make it be if you fire and forget, because the

if spacekey()=1
launch code
endif

you have to hold spacekey,
ill look more into it now but if anyone knows please post
if i find it out ill post it too
any way to the point , heres a simple Z coordinate launch code with angled trajectory, ill try and REM it later.
[EDIT]
okay i rem'd it and spaced it out




[EDIT]

okay new code with fire and forget

i put REM CHANGE on the parts i changed

basically make a variable 0
then set the variable to 1 if space bar is pressed
then when the object is deleted set the variable to 0



[EDIT]

okay just some timer based power increase

and a little update, just finished watchin that 70's show and im goin to bed
(Thanks to butter fingers for the timer help)



[edit]
i realized there was a problem in the code above so,

fixed:


i still have to fix the power variable to a float because 4,5,6,7 are all the same power level because the power is divided by 4. and an integer wont work like that



[edit]
i dont know why but i have been stuck on this code like ugly on a gorilla. i just added more variable control and reset variable code pieces.
Im going to try to add bouncing on the matrix.

here


Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st Jan 2010 23:13
divvie it up into x, y, and z components.

Say you have a tank on a planet with G gravity, whose cannon is rotated at an angle of xr,yr,zr. The x, y, and z components of the projectile's velocity after being fired with force F is this:

x=(cos(xr)*cos(zr)*sin(yr)+sin(xr)*sin(zr))*F
y=(cos(xr)*sin(zr)*sin(yr)-sin(xr)*cos(zr))*F
z=cos(xr)*cos(yr)*F

it's complicated cuz o' euler rotations. If your object has 0 rotation on the z axis, then that simplifies to:

x=cos(xr)*sin(yr)*F
y=-sin(xr)*F
z=cos(xr)*cos(yr)*F


Tony Martin
15
Years of Service
User Offline
Joined: 5th Jun 2009
Location:
Posted: 23rd Jan 2010 20:37
THAT'S very interesting Neuro, I've been implementing the equations found here:

http://www.ac.wwu.edu/~vawter/PhysicsNet/Topics/Vectors/ProjectilesMotion.html

But what you posted look completely different! I understand there are many ways to solve a problem, but I'm wondering if maybe I've been searching for the wrong thing all this time....

Can you tell me more please?
Thanks!
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 23rd Jan 2010 23:32
basically i just found the way the cannon was pointing and multiplied that direction by a force vector. You can do two things from there, one would be to keep the x, y, and z variables as speed variables for the projectile, while decreasing the y value by a small amount per frame to act as gravity. Then keep moving the projectile by the x, y, and z speeds each frame until it collides with something.

If you just want to find out other stuff like where the projectile hits, at what speed does it hit, and after what time, then you can get into all that projectile motion stuff. I can work through the math on that if you want - I've done it before, but I've misplaced teh codez :\

If you have a 3d terrain, then you would have to do a bunch of raycasts along the arc path that the projectile travels, to get the point that it hits the ground at. Then, using that, you could calculate how much time until it hits the ground, as well as the force/speed that it hits the ground with.


Login to post a reply

Server time is: 2024-11-24 20:34:07
Your offset time is: 2024-11-24 20:34:07