#### Archived

This topic is now archived and is closed to further replies.

# Projectile Problem

This topic is 5781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am trying to implement a cannon in a 3d enviroment. I have succeeded in two dimensions with; //Set initial XY velocitys m_oShell.velX=m_oShell.velocity*cos(m_oShell.angle); m_oShell.velY=m_oShell.velocity*sin(m_oShell.angle); //Update Position m_oShell.vLoc.x+=m_oShell.velX*m_fTimeElapsed; m_oShell.vLoc.y+=m_oShell.velY*m_fTimeElapsed; m_oShell.velY-=m_oShell.gravity*m_fTimeElapsed;//apply gravity This works just fine, but now i wanted to add the direction the cannon is pointing. //Initial... m_oShell.velX=m_oShell.velocity*cos(m_oShell.Direction);//direction of cannon m_oShell.velZ=m_oShell.velocity*sin(m_oShell.Direction); m_oShell.velY=m_oShell.velocity*sin(m_oShell.angle); //angle of cannon //Update m_oShell.vLoc.x+=m_oShell.velX*m_fTimeElapsed; m_oShell.vLoc.z+=m_oShell.velZ*m_fTimeElapsed; m_oShell.vLoc.y+=m_oShell.velY*m_fTimeElapsed;//height m_oShell.velY-=m_oShell.gravity*m_fTimeElapsed; This works, but only up to 45 degrees. I know it has something to do with the horizontal distance not decreasing when it goes over 45 degrees, but I can''t work out how to fix it. Any help or advise would be much appriciated, Thankyou

##### Share on other sites
assuming angles are measured counter-clockwise looking down the positive axes in a left-handed system

A = ccw from +ve Z in the ZY plane
B = ccw from +ve X in the ZX plane

elevation first (s=speed)

z=s*cos(A)
y=s*sin(A)

pan

z=s*cos(B)
x=s*sin(B)

putting them together
x=s*sin(B)
y=s*sin(A)
z=s*cos(A)*cos(B)

********

A Problem Worthy of Attack
Proves It''s Worth by Fighting Back

##### Share on other sites
Thanks for the reply.
I have been tinkering with the code for another hour with your help, my code now looks like this;

//Initial values
m_oShell.velX=m_oShell.velocity*sin(-m_oShell.Direction);//Pan
m_oShell.velY=m_oShell.velocity*sin(m_oShell.angle);//Elevation
m_oShell.velZ=m_oShell.velocity*cos(m_oShell.angle)*cos(m_oShell.Direction);

//Update
m_oShell.vLoc.x+=m_oShell.velX*m_fTimeElapsed;
m_oShell.vLoc.y+=m_oShell.velY*m_fTimeElapsed;//Height
m_oShell.vLoc.z+=m_oShell.velZ*m_fTimeElapsed;

m_oShell.velY-=m_oShell.gravity*m_fTimeElapsed;//Apply gravity

but it''s still gives the apperance of shooting at a 45 degree angle, i.e impossable to shoot your self.

Again any further help would be much appriciated, thanks.

##### Share on other sites
im not entirely skilled enuf to correct or base on ur code... but in a particle system module ''ve worked on before, i use the following method to identify the direction of motion for the particles.
it allows directional control over an upper hemisphere.

Velocity.x = sin(fPitch) * sin(fYaw);
Velocity.y = cos(fPitch);
Velocity.z = sin(fPitch) * cos(fYaw);

pitch and yaw are simpler way of denoting direction, IMHO. pitch is when u look up and down, yaw is left and right... hope it works for you.

##### Share on other sites
Yep that seems to more or less work, Thankyou. Just one more problem to iron out. If My Barrel is Pointing to the sky (90 degrees(1.57 radians)) My Shell come out horizontal and if my barrel is horizontal my shell come out vertical... I''m sure i''ll work it out. Thanks again.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632988
• Total Posts
3009736
• ### Who's Online (See full list)

There are no registered users currently online

×