apply force

Feb 10, 2010 at 11:30 AM

Hi !

I apply fixed force to my object and then i apply force in inversed direction with the same force, but in cycle dividing into 10 parts thats are summary equals to the whole fixed count = force.

For example:

at first:

1) boxBody.ApplyForce(fireForce);

then

2)  while ((counter++ == 9))

      {          

           boxBody.ApplyForce(- fireForce / 10);     

       }

 

Would this method return accurately my object  to it`s beginning place?

Feb 10, 2010 at 2:38 PM
Edited Feb 10, 2010 at 2:43 PM

Hey, I'm somewhat of a newb around here, but I'll try to answer the question.

 

First, I do not think that there is enough information here, unfortunately. Describe

the environment for the object. Is there a surface this object is on? What's the gravity

of the world? Does the floor the object is resting on have any friction?

 

Second, think about physics.

Assume you put a 100N force at zero degrees on a frictionless floor at zero degrees as well.

Each second for 10 seconds, you apply a 10N force in the opposite direction. By the tenth

second, the net force is 0N on the object, meaning that the object is completely decelerated

with zero velocity. The object at no point was moving in the opposite direction, therefore, it

did not return to its beginning place.

 

Third, I'm not sure I understand the "(counter++ == 9)" logic, but that may be just me on this

one. It looks like that loop will only happen at most once.

 

Finally, I'm not exactly sure how ApplyForce works in relation to real physics. Force implies

an acceleration, and time is important in determining how fast the object is moving, so I

don't know how "fast" this force is applied, but as long as all "ApplyForce" calls apply a force

for the same period of time, then my "Second" still works I believe.

 

Good luck!

Feb 10, 2010 at 8:12 PM
oranjoose wrote:

>>First, I do not think that there is enough information here, unfortunately. Describe

>>the environment for the object. Is there a surface this object is on?

Now the object is not on any surface.

>>What's the gravity of the world?

The gravity is absent, because the camera view is above the object. You can see the map (landscape)  and the tank. Player can use WASD keys to control the tank.

>> Does the floor the object is resting on have any friction?

The floor does not have any frictions  with tank - i even did not think about it yet.

 

>>Second, think about physics.

>>Assume you put a 100N force at zero degrees on a frictionless floor at zero degrees as well.

Yes.

>>Each second for 10 seconds, you apply a 10N force in the opposite direction. By the tenth

>>second, the net force is 0N on the object, meaning that the object is completely decelerated

>>with zero velocity. The object at no point was moving in the opposite direction, therefore, it

>>did not return to its beginning place.

Ok.

Imagine that  tank stays at zero degrees. It has a base, a tower and a cannon tube. My idea is when player click Fire-button, the cannon-tube immediately go into tower and then move back to it`s beginning position with some pause. It looks like tank shoot.

>>Third, I'm not sure I understand the "(counter++ == 9)" logic, but that may be just me on this

>>one. It looks like that loop will only happen at most once.

Sorry i missed one string before this cycle (counter=0;)

Cycle repeats 10 times.

>>Finally, I'm not exactly sure how ApplyForce works in relation to real physics. Force implies

>>an acceleration, and time is important in determining how fast the object is moving, so I

>>don't know how "fast" this force is applied, but as long as all "ApplyForce" calls apply a force

>>for the same period of time, then my "Second" still works I believe.

May be there is other way to realize my idea with shooting?

>>Good luck!

Thanks.

 

Feb 10, 2010 at 9:32 PM

Firstly, there's a difference between applying force and impulse. As oranjoose said, you need to apply a force over time to accelerate a body, so applying a force in a single frame (as opposed to multiple frames over time) will not give you the desired effect. However, impulse instantly modifies the velocity of the body, therefore applying an impulse in a single frame will instantaneously cause the body to move.

Now, if I understand your intent correctly, what you want is to simulate the motion of the cannon tube when a shot is fired (moving out and then in). If so, there are a couple of ways I can think of doing this.

The first (and easiest, in my opinion) is to simply use a sprite animation.

The second is to use a linear spring to connect the tower and cannon tube and an angle limit joint to restrict relative rotation. With this, you can apply an impulse to the cannon tube and it will protrude and return to it's rest position (eventually). You'll obviously have to tweak the spring params to get the desired behaviour, but it could work quite well.

The final approach is to just hard code a timed animation, i.e. change the position of the cannon tube so that it appears to be protruding out, wait some time, change it's position back. Depending on how you time this, it could look quite good. Of course, you could go one step further and add some intermediate positions.

Anyway, hope this helps.

Feb 11, 2010 at 9:21 AM

Thank you. It is quite clear for me now.