# Calculating force necessary to reach arbitrary point

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

## Recommended Posts

Hello. This one's been bothering me for a week or so. I'm trying to write code that calculates the force necessary to reach an arbitrary point in space (for NPC movement). I tried over at the Newton forums with little response, but the problem isn't with the engine itself. I'm doing (pseudocode):
necessaryForce = (distance - (velocity-velocity*0.6)) *npcMass /delta

They're all floats. It is based on f=ma (subtracting current velocity from the velocity necessary to reach the waypoint to find the necessary change in velocity, then dividing by the physics engine's timestep, as acceleration=delta velocity/delta time). So "distance" is just the NPC's distance from the waypoint , velocity is its current velocity (in m/s), npcMass is the NPC's rigid body's mass, and delta is the physics engine's timestep (returned in seconds, so it's usually <0.015). The "-velocity*0.6" is my lame attempt to take friction into account, which actually seemed to work quite well. Now, it's pretty damn close, to the extent that it almost suffices (not for an action game, unfortuantely). The problem is that the force applied when the NPC approaches the waypoint (<1m away) is too low, so it kind of "eases" towards it. Also, the necessaryForce itself seems to always fluctuate between a very large and a very small value as the NPC approaches, which I can't explain. I'd appreciate if someone could explain what's wrong with my method, and point to a better one. Thanks.

##### Share on other sites
Quote:
 Original post by BaiameThe "-velocity*0.6" is my lame attempt to take friction into account

That looks like a red flag right there. There is no friction in Space.

I also don't see why distance is relevant here.
You take your current velocity, then compare to a proposed velocity which passes through the target. The difference between them is the total acceleration needed.
This gets divided by delta to return the acceleration for this timestep.
-im not seeing how distance ever needs to show up here.

I would expect soemthing more like this:

forcenow=(velocityneeded-velocity)/delta

Also, I'm assuming your Spaceship only needs to pass thru the target(like a waypoint), not stop and land there, right?

P.S. I'm guessing that the wierd fluctiation you saw has to do with the friction stuff. Lose the friction and I'd bet it goes away; you don't want it in Space anyhow.

##### Share on other sites
So, if I understand correctly, you want to figure out how hard to whack something (e.g. a golf ball) such that it will come to rest at a certain spot (e.g. at the hole)?

I presume that friction is constant (e.g. your already on the green and it is completely level)?

Does my golf ball analogy hold up?

##### Share on other sites
Doh, cross-post.

Oh so this is in space, and you don't want to simply 'reach' the point, you want to go 'through' it? What speed to do you to be as you go through it?

The friction stuff threw me as well.

##### Share on other sites
Sorry, my first post was extremely misleading. I'm aware that there's no friction in space. I was referring to Euclidean space. I'm trying to move NPCs across the ground (testing on flat parts of a terrain). In fact, the point is not totally arbitrary; it is always a fixed distance above the ground. If you see something horribly wrong with the friction part of it, please point it out.

About velocities. Consider that the physics engine returns velocities in m/s. The distance in meters is the necessary velocity in m/s (as the time delta in this case is 1 second). Dividing by the physics timestep (also in seconds) should give you the acceleration, no?

Thanks for your help so far, everyone.

EDIT- And for further clarification the "points" I'm referring to are waypoints for my NPCs to stop at.

##### Share on other sites
necessaryForce = (distance - (velocity-velocity*0.6)) *npcMass /delta   (1)
reduces to :
necessaryForce = (npcMass *(distance - 0.4*velocity)) /delta    (2)
which is just a line with nF increasing with distance but constrained by velocity (that is as velocity increases max(nF) -> -∞)). What are your variables? Is velocity a constant, is equation (1) the same as what is in your code? Your code doesnt seem very physical.

##### Share on other sites
Well, if this is actually about characters Walking on the Ground, then I'd say the entire 'find force necessary' approach really doesn't make sense here.

Find a force like that makes sense in space, since thats how a rocket would work, by using force to make a course/path adjustment.

Walking on the ground though; well people dont have rockets, they have feet.
Friction and your leg mechnics really dominates the physics here. Its not so much about force or acceleration since you don't really do much of that.
For the most part when walking you can change direction pretty arbitrarily with minimal change in overall speed...

I'd just have my character get pointed in the right direction, and keep walking within the limits of how fast he can walk/run. stop walking and stand still when he gets there.

Even if you want your character to Run instead of Walk, there's not so much an acceleration as there is a transition from one mode to the other... nothing to be that significant I'd say.

##### Share on other sites
Quote:
 Original post by BaiameAbout velocities. Consider that the physics engine returns velocities in m/s. The distance in meters is the necessary velocity in m/s (as the time delta in this case is 1 second). Dividing by the physics timestep (also in seconds) should give you the acceleration, no?Thanks for your help so far, everyone.EDIT- And for further clarification the "points" I'm referring to are waypoints for my NPCs to stop at.

You have v = delta_x / delta_t with delta_t = 1. so v is correct. But a <> v / dt.

##### Share on other sites
Daerax, I don't entirely understand your posts. Are the variable descriptions in my first post insufficient? Maybe I should point out that 0.6 is just the friction coefficient of the surface below the NPC, and I just put the number straight in as I don't know how to return a friction coefficient using the physics library. What do you mean by "a <> v / dt."?

haphazardlynamed, since I need a physics engine for other purposes anyway, I suspect that calculating the necessary force is the easiest method in the long-term. And in my experience, acceleration and deceleration when running have a significant effect. Infinite acceleration and deceleration in a game would be very noticeable and unconvincing.

##### Share on other sites
Hey.

Quote:
 The distance in meters is the necessary velocity in m/s (as the time delta in this case is 1 second). Dividing by the physics timestep (also in seconds) should give you the acceleration

Is the same thing as a = v /dt. But a = dv / dt. Aceleration is a, dv and dt are change in velocity and time.

----
What I mean about your equation is I am not sure why you are dividing mass by time? Like I said it reduces to: m(d - .4v)/dt.

Also how do you calculate your velocity when solving for force?

[Edited by - Daerax on March 19, 2007 7:09:29 PM]

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999981
×