projectile motion

Moderators: Disciple, zlovatt

Post Reply
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

hi guys,
i was doing a search but couldn't find what i need.
is there a way to use projectile motion with expressions? say, i have a bunch of layers that i want to blast in a certain direction (with variations). is there a way to set angle and velocity and gravity and trigger from a layer maker?
i failed every physics exam i ever did in high school, so this is not my strong point. hopefully something exists... i have a pre-build expression for flame but the syntax is not strict javascript i don't think, and i don't think my skill level is up to porting the expression to AFX yet.

many thanks,
scott.
Colin Braley
Posts: 13
Joined: July 14th, 2005, 7:33 pm
Location: VA
Contact:

Code: Select all

initialVeloc = 93;
simSpeed = 7;
gravity = 9.8;
launchAngle = 70;
launchPoint = [ 72 , 452 ];
//---------
t = time * simSpeed;
a = [ 0 , gravity ];
initialVx =  initialVeloc * Math.cos( degreesToRadians( launchAngle) );
initialVy =  initialVeloc * Math.sin( degreesToRadians(- launchAngle) );
v = [ t * a[0] + initialVx , t * a[1] + initialVy ];
p = [ ((t * t * a[0]) /2 ) + initialVx * t + launchPoint[0] , ((t * t * a[1]) /2 ) + initialVy * t + launchPoint[1] ];
p

If you want to randomize the variables try this instead:

Code: Select all

seedRandom( index , true );
initialVeloc = random( 75, 100 );
simSpeed = 7;
gravity = 9.8;
launchAngle = random( 40, 70 );
launchPoint = [ 72 , 452 ];
//---------
t = time * simSpeed;
a = [ 0 , gravity ];
initialVx =  initialVeloc * Math.cos( degreesToRadians( launchAngle) );
initialVy =  initialVeloc * Math.sin( degreesToRadians(- launchAngle) );
v = [ t * a[0] + initialVx , t * a[1] + initialVy ];
p = [ ((t * t * a[0]) /2 ) + initialVx * t + launchPoint[0] , ((t * t * a[1]) /2 ) + initialVy * t + launchPoint[1] ];
p
Just change the numbers that are in the random( min , max ) function.

don't know what you meant when you were talking about layer markers however, so I can't help you there unless you can reexplain that part.



~Colin
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

This should launch at the first layer marker:

Code: Select all

vel = 300; //velocity  - pixels per second
angle = -45; // launch angle - degrees
g = 300; // gravitational constant 

if (marker.numKeys > 0 && marker.key(1).time < time){
  t = time - marker.key(1).time;
  theta = degreesToRadians(angle);
  x = vel*Math.cos(theta)*t;
  y = vel*Math.sin(theta)*t  + g*t*t/2;
  value + [x,y]
}else{
  value
}
Dan
Post Reply