PhysX Actor constrain movement flags.

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 1024 Views - Last Post: 31 July 2013 - 01:27 PM Rate Topic: -----

#16 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Re: PhysX Actor constrain movement flags.

Posted 30 July 2013 - 10:00 AM

I learned from someone who does Physics that if you apply the negative force the gravity applies to an object it keeps falling but it doesn't keep on falling faster. So it's always the same speed.
So... I guess I'm back to square one.
Was This Post Helpful? 0
  • +
  • -

#17 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: PhysX Actor constrain movement flags.

Posted 30 July 2013 - 12:56 PM

I do physics too. Please ask them to explain that.
Was This Post Helpful? 0
  • +
  • -

#18 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Re: PhysX Actor constrain movement flags.

Posted 30 July 2013 - 01:15 PM

Well, you know. If you're falling from a plane there's gravity that's pulling you down but because of the resistance of the air that is pushing you away there is some kind of an equality of forces in both ways. (So the force of the gravity and the one of the air) so you are in a kind of state where you don't further accelerate but keep falling at the maximum km/h or mph.

Well, this is what she explained. But I guess PhysX is in some kind of vacuum... I don't actually know that.

So still, if I add a negative force to my object it'll come back down somehow. I tried "Debugging" it and I'll keep doing this for some time until I find some useful information. I've looked at Velocity and Momentum so far when the custom force is applied.
Was This Post Helpful? 0
  • +
  • -

#19 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 591
  • View blog
  • Posts: 1,317
  • Joined: 24-April 12

Re: PhysX Actor constrain movement flags.

Posted 30 July 2013 - 02:08 PM

Yes. This is still somewhat related to buoyancy. When you fall through the air, you are carving out an air column in the shape of you falling. All that air in that column must be pushed aside in order for you to fall. (Air is a gaseous solution, and so it "easily" moves out of the way.) But you are still displacing that column of air. The faster you fall, the longer the column becomes because there is a greater distance you are traveling through before air can come back in and fill the vaccume. You're pushing aside more air per second and so the resistance force increases as you try to push greater volumes of air out of the way over the same time period (because you're moving faster and faster).

When you're moving horizontal, this is known as "drag". When you're falling it's called "terminal velocity" once the air column you are pushing aside weighs enough to counter-act the acceleration of gravity. Note, it does not decrease your speed (velocity). It mearly prevents you from speeding up any more, which is why its called "terminal velocity".

Not sure, how PhysX sees it though. If I get a chance, I think I may try to check out PhysX.
Was This Post Helpful? 0
  • +
  • -

#20 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: PhysX Actor constrain movement flags.

Posted 30 July 2013 - 03:56 PM

You are not simulating air resistance in the way that you think. In physics engines in games everything is calculated around:

1. Vectors.
2. Time.
3. Planes.

We simulate the effects of air resistance by damping a force in the direction of the vector rather than create a volume of air with all its countless molecules, simulating how air would provide such resistance in the real world. Remember that game physics only needs to be convincing, not actually an accurate emulation of nature.

This post has been edited by ButchDean: 30 July 2013 - 03:57 PM

Was This Post Helpful? 0
  • +
  • -

#21 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 591
  • View blog
  • Posts: 1,317
  • Joined: 24-April 12

Re: PhysX Actor constrain movement flags.

Posted 30 July 2013 - 05:38 PM

First, I absolutely agree with Butch that a physics simulation in games is the kindergarten version of actual physics. If it looks good and feels right to the user, no one cares if it uses real physics and a lot of that may just be wasted computational power. In the real world, you are talking about calculus equations that are way beyond my understanding. Even scientific physics simulations may not take into account absolutely everything. In fact, it's almost 100% certain that they don't. It's mostly a game of "it's good enough".

Also, one might be sad to find out that scientists don't know everything. A whole lot of the time they have no way of knowing something. For example, how much friction does a tire have with the ground? The answer is that science doesn't know. Engineers will take an actual tire out and measure it to find out, but there's no math formula for it.

But back to the question. I was looking over the PhysX documentation. I thought I would find a method for acceleration. That seems suspiciously absent. What they have is linear velocity and linear momentum. And it tells you right up front that if you keep setting it that gravity isn't going to work.

Quote

virtual void NxActor::setLinearVelocity ( const NxVec3 & linVel ) [pure virtual]

Sets the linear velocity of the actor.

Note that if you continuously set the velocity of an actor yourself, forces such as gravity or friction will not be able to manifest themselves, because forces directly influence only the velocity/momentum of an actor.

The actor must be dynamic.

Sleeping: This call wakes the actor if it is sleeping.


Parameters:
[in] linVel New linear velocity of actor. Range: velocity vector

Platform:
PC SW: Yes
PPU : Yes
PS3 : Yes
XB360: Yes
See also:
getLinearVelocity() setAngularVelocity() NxBodyDesc.linearVelocity


Oh wait. I forgot that acceleration is caused by an impulse force. I just needed to look for the word "impulse".

It appears to me that you can apply a force, or impulse (or acceleration), to your object. There is a constant impulse of 9.8m per second applied every second on earth to everything towards earth's center. I saw a way to set such gravity in PhysX, but you've probably got that part figured out. In order to fly, you have to counter-act that. In order to float, you have to apply an impulse force of 9.8 m per second every second in the exact opposite direction. To rise, you must apply a stronger impulse than that. To fall slowly, you need to apply that impulse with less acceleration than 9.8 m per second.

I don't see where it says what units this is in. (Typical crappy documentation.) It's probably in meters per second per second, or meters per second per frame, or possibly its in Newtons since it says that its a force.

http://en.wikipedia....i/Newton_(unit)

It probably is Newtons since it is described as a force, rather than an acceleration.

Force (in Newtons) = mass (in Kg probably) * acceleration (in meters per second each second)... probably.

That means a Newton is the same thing as a kilo-gram-meter per second squared. Or in English, enough force to accelerate a kilogram by 1 meter per second every second assuming we are in outer space where there is nothing like air to interfere with our diabolical schemes.

If you apply this force at an angle to the force of gravity, you should get lateral movement along with your flying. Just angle your vector to not be perfectly (but oppositely) aligned with the gravitational force. I assume you know what we mean by vector here. If not, I'll explain, but as far as you've come, I assume you've got that down.

Don't forget to set your actor's mass and such, of course.

Does this get you there?


Quote

virtual void NxActor::addForce ( const NxVec3 & force,
NxForceMode mode = NX_FORCE,
bool wakeup = true
) [pure virtual]

Applies a force (or impulse) defined in the global coordinate frame to the actor.

This will not induce a torque.

NxForceMode determines if the force is to be conventional or impulsive.

The actor must be dynamic.

Sleeping: This call wakes the actor if it is sleeping and the wakeup parameter is true (default).


Parameters:
[in] force Force/Impulse to apply defined in the global frame. Range: force vector
[in] mode The mode to use when applying the force/impulse(see NxForceMode)
[in] wakeup Specify if the call should wake up the actor.

Platform:
PC SW: Yes
PPU : Yes
PS3 : Yes
XB360: Yes
See also:
NxForceMode
addForceAtPos() addForceAtLocalPos() addLocalForceAtPos() addLocalForceAtLocalPos() addLocalForce()

This post has been edited by BBeck: 30 July 2013 - 05:44 PM

Was This Post Helpful? 1
  • +
  • -

#22 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 591
  • View blog
  • Posts: 1,317
  • Joined: 24-April 12

Re: PhysX Actor constrain movement flags.

Posted 30 July 2013 - 05:54 PM

Just went back and re-read this thread and realized I'm just repeating what's already been said. Butch pretty much gave the answer.

But, the force you should need should be the mass of your object in kilograms times 9.8 m per second and this force needs to be applied again every one second. This should cause your object to levitate, assuming its already in the air and that this force vector is pointing in the exact opposite direction of gravity. If this doesn't work, they are probably using different units than this. But metric (SI) is a physics standard, so they probably are staying consistent. Or you are not applying this force exactly every one second. Consider that you may be applying it every Update() frame which may be 60 frames per second or some other speed. That would be 60 times every second and not once per second.

Any additional force should cause the object to rise, and anything less should let it fall to the ground and various speeds. If your force becomes angled, because - for example - you want to use this force to also apply forward movement, your force will have to increase to compensate for the fact that some of the force is being drained off in the form of forward movement. You'll have to increase the force to stay aloft.

You can imagine this force as a rocket engine. As long as this force is being applied every second, the engine is on. If you stop applying it, you've just turned the engine off. Angling the engine will cause lateral movement.

I'm also assuming that you've correctly set your gravity to 9.8 in your game and you probably have to have your actor's mass defined too.

This post has been edited by BBeck: 30 July 2013 - 06:02 PM

Was This Post Helpful? 0
  • +
  • -

#23 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: PhysX Actor constrain movement flags.

Posted 30 July 2013 - 06:18 PM

View PostBBeck, on 30 July 2013 - 09:38 PM, said:

First, I absolutely agree with Butch that a physics simulation in games is the kindergarten version of actual physics.

But I wasn't saying that. Game physics is actually very complicated because we are trying to simulate real world, computationally intensive interactions on constrained hardware. We have to take into consideration how you can balance as realistic as possible physics with the numerical constraints (you can't represent infinite and infinitesimal quantities in 64 bits), speed constraints (there are only very few bodies in a scene that you can calculate physical interactions with), and the sharing of resources (you have other game subsystems running too with their own demands).

It certainly is not kindergarten.

View PostBBeck, on 30 July 2013 - 09:38 PM, said:

If it looks good and feels right to the user, no one cares if it uses real physics and a lot of that may just be wasted computational power.

Yes you are right, nobody cares how accurately physics is simulated at the computational level. But computational power WILL be wasted if we tried to accurately model physics in games.
Was This Post Helpful? 0
  • +
  • -

#24 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 591
  • View blog
  • Posts: 1,317
  • Joined: 24-April 12

Re: PhysX Actor constrain movement flags.

Posted 30 July 2013 - 06:41 PM

Maybe Kindergarten was a poor choice of words. I merely meant that you are correct that it is not necessary or desirable to simulate the molecular forces between air molecules including all the various different gases found in air such as Nitrogen, Helium, Oxygen, etc. and their various molecular densities as they resist your object and force it to stay within the confines of terminal velocity let alone the price of tea in China and how that may cause people to consume more or less plants and the effect that has on the earth's atmosphere and the ratio of gases within it.

:-)
Was This Post Helpful? 0
  • +
  • -

#25 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Re: PhysX Actor constrain movement flags.

Posted 31 July 2013 - 09:01 AM

Thanks BBeck. Your last posts were very interesting to read and help very much in how I should apply this problem in my game. I guess I figured out that I should set my object somewhere in space and then apply the addForce() EVERY SECOND. Now I'm doing that every frame.
Also, I'll try to figure out which formula I should use to get the right force to apply in the opposite direction.
Thanks by the way for also explaining to me, or anyone who reads this thread, what should happen if you angle the vector (yes I know what a vector is :)/>/> ).

At the moment, my object is spawning a bit "in" the ground plane of PhysX so it get's boosted out a bit. If I then apply my opposite force every update it goes up some more but then starts falling again. I guess this could be due to my object not spawning in a "free" environment. I'll change this today.

I figured out they use the Velocity and Momentum things as well. I tried them both but they didn't seem to do much difference to the object.

I'll let you guys know about the progress I'm making if you're still interested. (otherwise, I will as well so others can learn from this)

@Butch: Can I assume that PhysX actually works with some kind of vacuum? Or does it do some calculations on the air that might be in the scene?
I guess I have to take that in account because of what you said earlier

Quote

We simulate the effects of air resistance by damping a force in the direction of the vector


Thanks again for the quick response and I'll let you guys know how it goes. :)
Was This Post Helpful? 0
  • +
  • -

#26 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 591
  • View blog
  • Posts: 1,317
  • Joined: 24-April 12

Re: PhysX Actor constrain movement flags.

Posted 31 July 2013 - 09:24 AM

I'm interested in the progress you make. I would like to take some time to play around with and learn PhysX, but I've got more projects going on currently than I can handle, and I might need to make more progress with DX11 before I focus on PhysX. So far, I've been trying to handle my own physics, but if nothing else, it would be very good to see how a physics engine does it. The closest I've come to a physics engine is playing around with some of the settings in the old Torque 3D engine, where physics was just a small part of it and probably more obfuscated.

Butch mentioned damping. I saw some damping functions in the PhysX documentation.

I got the impression that the Velocity and Momentum functions were there to set an initial Velocity or Momentum, so that you have the option of starting out with an object in motion, and not for updating the velocity or momentum based on the fact that the documentation says that changing them constantly (by using the Velocity and Momentum functions) will cause the simulation to fail.

It would probably be very educational to see exactly what force causes the object to levitate (be perfectly balanced between rising and falling). If you knew the exact amount of force applied per frame to do that, you could probably figure out what units the force is in. Theoretically, it "should" be (the mass of your object in kilograms - that you told the engine - times 9.8 meters per second - which you defined to the engine as your gravity) divided by the number of frames per second that your game is currently running at [or the number of times per second the function is getting called, which should be the same thing]. Anything beyond that should cause the object to rise as long as this force is applied every frame and applied in the exact opposite direction of gravity. If that formula is not doing the trick, then probably they are using different units somewhere, or I'm misunderstanding what they mean by "force". There could also, theoretically, be a downward force that I haven't accounted for that must be counteracted; I don't know what that would be, but doing something like applying additional downward force in the code would do that.
Was This Post Helpful? 0
  • +
  • -

#27 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Re: PhysX Actor constrain movement flags.

Posted 31 July 2013 - 11:20 AM

Just to keep you guys updated.

I changed some things to the actor creation. Now my model is responding correctly if I give it a spawning position. So... I guess that adding new forces the object could work better now.

I'm currently changing the model to a smaller size since it seems to very large in the scene. I also added a mass to it of which I'm sure it's the right value to work with. I think I'm almost there.

If I get it working I'll definitely post some code or an explanation on how it's actually done.
I'm excited :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#28 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Re: PhysX Actor constrain movement flags.

Posted 31 July 2013 - 12:39 PM

HEY GUYS! I FOUND IT!

It's a bit weird but hey, it does the job. So, let me explain.

1) What I needed to do was indeed like Butch said first that I needed to apply the same force in the opposite direction the gravity is pulling me.

2) Some mistakes were made while creating the PhysX actor and attaching it to my object. One time my airplane was falling upwards without any added force aside from the gravity. I also noticed that a non-custom object didn't do as it was supposed to when the airplane was added to the scene.

So I checked my scene with the PhysX Visual Debugger software which is EXTREMELY helpful by the way if you want to do PhysX programming and it showed me some very weird things. I started checking my code and found out that I added 2 actors by accident. After that was fixed my object actually fell like it was supposed to.

3) Then I started testing with the force I needed to keep my airplane floating. I started with
addForce(NxVec(0, massOfObject * gravity * 60, 0))
but that didn't seem to work properly. So eventually I started with a number that I saw changed something to the position of my object and from that number I started testing some other values until I got the "magic number" that kept my object in the same place.

4) The final formula I used is:
addForce(NxVec(0, 18785 * gravity, 0))
and this for every frame.
My object doesn't seem to have a mass at the moment (working with some files I got from school) but I'll try it out and let you know.

If anyone has any questions please ask them so I can explain some more.

Butch and BBeck, thank you so VERY VERY much for your help. I think that, with all the information I got from you two, that I can complete the movement of my airplane in my game. Do you guys think this is the right way to do it? Like I did it right now? Or do you still have some ideas/questions/remarks?
Was This Post Helpful? 2
  • +
  • -

#29 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: PhysX Actor constrain movement flags.

Posted 31 July 2013 - 01:27 PM

Excellent work, apart from that '18785' magic number. You should be deriving it from somewhere, but that's not very important right now.

Well done! :)
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2