View unanswered posts | View active topics It is currently Fri Dec 27, 2024 11:10 pm



Reply to topic  [ 8 posts ] 
 How to use AddForce and whats the difference? 
Author Message

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post How to use AddForce and whats the difference?
So I went to check for a function in the wiki to add force to an object, but the docs are pretty unclear whats the difference between the following:

AddForce()
AddAbsForce()
AddImpulseForce()

Whats the difference between these guys and how to use them right?
For AddForce it said to define a vector, a value and another vector. I dont know why or how it works but doing it as it said in the docs didnt work.

How do I use these? How am I supposed to write the statement for it.


Tue Sep 15, 2009 11:06 am
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Re: How to use AddForce and whats the difference?
I apologize in advance for the long winded reply.

I haven't really done much with force on CC, but I know a few things about these functions.

AddForce() applies a force to an object. By force, it means the force defined in Newtons Second Law: Force = mass * acceleration (or the rate of change of momentum with respect to time). This is measured in Newtons (N). 1 Newton is the force needed to accelerate a mass of 1 kilogram to 1 meter per second, within 1 second. In terms of units, that is: N = kg*m/(s^2). (m stands for meters, not mass).

AddAbsForce() I believe is the same as AddForce() except it takes the absolute value of the force before applying it.

AddImpulseForce(), however, is slightly different from the other two. Instead of appling a force, it applies an impulse. Impulse is measured in momentum, which is mass * velocity. For units, that's Momentum = kg * m/s.

So when do you want to use Force vs. Impulse force?

Use force when you want to effect an object's acceleration. However, I can't really think of a good example on how to use that at the moment.

Impulse force is useful for collisions and explosions. Say you want to simulate two soldiers colliding into each other. To accurately exert an impulse from one soldier onto the other, simply multiply that soldiers mass by his velocity and stick it into the ImpulseForce function. Done. The game handles the rest of the algebra involved.

I hope some of this helps.

**The vector you supply to the functions is the location on the body to apply the force, so that the game can simulate torque and rotation.


Wed Sep 16, 2009 5:13 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: How to use AddForce and whats the difference?
the best use of force i can see is for lua based rockets and stuff.


Wed Sep 16, 2009 5:41 am
Profile WWW

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: How to use AddForce and whats the difference?
My purpose is to make a head pop off the torso upwards.
So I'm trying to use force to "detach" an attachable pretty much.

One interesting thing I found in the Attachable class is the Detach() function, but this seems to completely delete the entire head instead of severing the link between its parent.


My guess is that I'm supposed to use AddImpulseForce, but I'm not entirely sure how to build the statement. So is this one correct?:

Code:
head.AddImpulseForce(Vector(0,0),Vector(0,-30));

--The purpose is to make it go up. Hence the Y -30 value.


Wed Sep 16, 2009 7:54 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: How to use AddForce and whats the difference?
reverse your vector's order.
Impulse vector, then offset vector, in meters.

oh also, now you're talking about Detach(), if you can, pester data about attachables that were attached with lua to something cause crashes if the thing they are attached to is removed from the scene (by gibbing or whatever else) before they are manually detached. putting detach in the Destroy() function of the object does ♥♥♥♥ all.


Wed Sep 16, 2009 9:26 am
Profile WWW
Banned
User avatar

Joined: Tue Feb 27, 2007 4:05 pm
Posts: 2527
Reply with quote
Post Re: How to use AddForce and whats the difference?
I apologize if this is a noobish response, but why not use this Detach() function then use a wound emitter that emits the head sprite? I have no idea if that would even work, just offering an outside suggestion


Wed Sep 16, 2009 12:28 pm
Profile YIM

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: How to use AddForce and whats the difference?
Sorry for bumping 3 day old thread, but negative jointstrength works great for popping things off.


Sat Sep 19, 2009 11:30 pm
Profile WWW

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: How to use AddForce and whats the difference?
Hey nice, I can even balance it more clearly with jointstrength than addforce, thanks Zalo!


Sun Sep 20, 2009 7:08 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.023s | 14 Queries | GZIP : Off ]