Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Math behind using llApplyImpulse to make prim go in a circle?

JoeTheCatboy Freelunch
Registered User
Join date: 14 Jun 2006
Posts: 42
09-05-2006 21:06
I'm wondering what the math behind using llApplyImpulse to move a prim around a central point. Also, I'm wondering if the Z position could be raised, and decreasing the radius of the circle the prim is going in. would llApplyImpulse be best for this? I want the effect to look like a prim with a particle system moving in a circle around the point, and raising so it spirals up to a central point.
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
09-06-2006 07:12
To answer the question, you need to apply the force along a tangent - untested, the code should look something like this...
CODE

vector tangent = llVecNorm(llGetPos() - center) * llEuler2Rot(<0, 0, 90>);
vector force = <1, 1, 0> * llGetMass() * 1.0;
force.x *= tangent.x;
force.y *= tangent.y;
force.z = llGetMass() * 9.8; // counteract gravity (need to check)
llApplyImpulse(force, FALSE);

...don't forget to set the object physical or this will have no effect

However, you may find it a LOT easier to control by creating an invisible root prim at the center point, making the particle prim a child and using llSetRot() and llSetPos to change the height.

hth,

/esc
_____________________
http://slurl.com/secondlife/Together
Kayla Stonecutter
Scripting Oncalupen
Join date: 9 Sep 2005
Posts: 224
09-06-2006 07:57
From: Escort DeFarge
However, you may find it a LOT easier to control by creating an invisible root prim at the center point, making the particle prim a child and using llSetRot() and llSetPos to change the height.
Agreed, or use llTargetOmega() for the rotation :)
_____________________
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
09-06-2006 11:15
Actually centripetal force is what causes an object to follow a circular path, and is always in the direction of the center of rotation (NOT along the tangent). For a mass 'm' in a circular path with radius 'r' and angular speed of 'w' (or velocity 'v'), the centripetal force has a value of:
f = m*v^2/r = m*(w^2)*r

Apply a force ('llSetForce()') of this magnitude in the direction of your axis of rotation and vary it often to correct for changes in position and you should be able to APPROXIMATE a circular path. You could do it with impulses also in the direction of the axis also but it will be more complicated.

Note however that I said APPROXIMATE. Why? Because you cannot apply a continuous force toward a point (except maybe with 'llMoveToTarget()', but we don't know the exact equation used for that function's force though we might be able to experiment or guess). So changing the force every 0.05 to 0.1 seconds (the accuracy of timers or sleeps) is going to introduce error. You'll just have to experiment to see how well it works (increase the value of the force to make the radius decrease, but this could also cause the motion to go haywire considering the error!).

The slower your motion and larger the radius the less your error is likely to be. Don't expect to be able to create a perfect little cenrafuge this way!!

To make the object also travel along the axis about which it is rotating, simply add an additional (vector addition that is) impulse/force parallel to the axis. You may also need some kind of initial impulse in the tangential direction to get the object moving (you shouldn't need a continuous tangent force except potentially to counteract some kind of friction or make up for some error in the motion as described above).

Good luck!
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
09-13-2006 09:00
From: Hewee Zetkin
Actually centripetal force is what causes an object to follow a circular path...

I agree, that is indeed strictly correct. However, the above code snippet has a critical attribute in its favor... and that is that it will work.

Regards,
/esc
_____________________
http://slurl.com/secondlife/Together
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
09-13-2006 17:16
From: Escort DeFarge
I agree, that is indeed strictly correct. However, the above code snippet has a critical attribute in its favor... and that is that it will work.

Not unless you are EXTREMELY lucky or the physics engine is really, REALLY screwed up it won't. At best you should get a path that very very quickly spirals outward from the center of rotation. Have you actually tried it?