PhysX Actor constrain movement flags.

  • (2 Pages)
  • +
  • 1
  • 2

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

#1 frostraver  Icon User is offline

  • D.I.C Head

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

PhysX Actor constrain movement flags.

Posted 28 July 2013 - 03:18 PM

Hi everyone,

I'm looking for a way to disable the addition of gravity to an actor in my scene.
I tried
m_pActor->raiseBodyFlag(NX_BF_DISABLE_GRAVITY);
like the PhysX documentation suggested but this doesn't seem to do anything.

Is there another way to do this? What I actually want to do is create an object that can "fly" so it shouldn't be affected by gravity. I know this is probably a wrong way to simulate this. I do want to be able to move in the Y axis though but not through the gravity.

Thanks in advance.

Is This A Good Question/Topic? 1
  • +

Replies To: PhysX Actor constrain movement flags.

#2 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,303
  • Joined: 22-October 08

Re: PhysX Actor constrain movement flags.

Posted 28 July 2013 - 05:18 PM

Regardless of whet the actor is flying, swimming or walking, gravity should affect them, except of you are on another planet which has no or little gravity.

To answer your question, I am unable to help at this time. I will have a look for you today.
Was This Post Helpful? 0
  • +
  • -

#3 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 28 July 2013 - 06:20 PM

Physics engines rely on gravitational forces and mass exclusively, so what you're asking is to remove an essential part of the engine whilst keeping all other forces true? If you really must remove gravitational forces to make a body appear to float, as I think you are suggesting, then you simply subtract the appropriate magnitude of the gravitational force from your final calculation. You should note that you will loose all motion simulation like a rising ballon because you have removed gravity.

Alternatively you can simply remove all Physx simulation from that particular body and simulate your own physical motion.

[edit]

Just found this, and to quote:

Quote

Is there any way to change the gravity vector per actor? For instance, if we wanted an actor to be able to walk up walls or have a scenario where the character’s gravity vector is constantly changing.

To disable PhysX gravity for an anctor call NxActor::raiseBodyFlag (NX_BF_DISABLE_GRAVITY).

Note: You should be careful changing gravity (or enabling/disabling) during the simulation. The change will not wake up sleeping actors (for performance reasons. It may be necessary to call NxActor::wakeUp () manually on affected actors.

However you will not neet to do that if you apply your own gravity to the actor, as the next step will wake up any actors necessary.

Use NxActor::addForce (force, NX_FORCE) to apply your per-actor gravity force to the actor in the direction and magnitude of the force vector (as specified in world space).

See the 2.3.1 User Guide, on the Guide>Dynamics>Actors>Applying Forces and Torques section for further information.


Which states what I was implying above.

Have fun! :)

This post has been edited by ButchDean: 28 July 2013 - 06:34 PM

Was This Post Helpful? 0
  • +
  • -

#4 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 29 July 2013 - 01:10 AM

Hi guys. Thanks for the answers already!
Butchdean, can you elaborate on how I would make the object appear to be floating? I have no idea on how I would make that calculation you're talking about.

To give you guys some context. The object is a plane controlled by the player.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#5 BBeck  Icon User is online

  • Here to help.
  • member icon


Reputation: 592
  • View blog
  • Posts: 1,321
  • Joined: 24-April 12

Re: PhysX Actor constrain movement flags.

Posted 29 July 2013 - 05:20 AM

I have to admit that I don't even really know what PhysX is (I have a vague idea; but I've never used it and don't know specifically what it is). But I do know Physics, the science. In other words, I know how it works in the real world even if I don't know how it works in your game.

So, thinking like a physicist:
Gravity is always in effect even when you're flying. Just ask a fighter jet pilot that's lost his engines (modern fighter jets are basically flying rocks without their engines).

Generally, you have two different effects that oppose gravity and both of them are essentially the same thing.

Let's start by thinking like a balloon.

The two different effects are buoyancy in a solution (air or water for example) and buoyancy between solutions. So, buoyancy in a solution is like a submarine under water, or a hot air balloon in the air. Buoyancy between solutions is what a boat is doing (the hull is in a liquid that has a certain buoyancy and the upper hull and masts and whatnot are in a gaseous solution we call "air").)

So, a boat is a special case because it has enough buoyancy to overcome the liquid water and float, but it does not have enough buoyancy to overcome the gaseous air and continue floating into the sky. And so you have two separate solutions (water and air) acting on it at the same time. Fortunately, buoyancy for subs and balloons is much more simple.

So the other effect is buoyancy in a single solution (like water or air only).

Let's think like a balloon. So, we have our hot air balloon (or helium or whatever) on the ground. It has mass, which we think of as weight. That mass is affected by the earth's gravitational field and accelerated towards the center of the earth. Every object has gravity, but it's gravity is based off of how much mass it has. You have gravity. Your body is causing things to move towards it right now. However, you don't have significant enough mass to have any significant gravity. Technically, our balloon accelerates the earth towards it while the earth also accelerates the balloon towards the earth. The are "technically" pulling each other closer to one another. However, the mass of the earth completely dwarfs any object actually on the earth. Your size and weight is nothing compared to the earths and our balloon's weight is also insignificant to the weight of the whole world. So, you can basically ignore the pull of the object itself, like the balloon, and pretend that only the earth itself has a gravitational field.

Off the top of my head, I believe that the gravitational acceleration of the earth is 9.8 meters square. Or in English, it's 9.8 meters per second each second. What that means is that anything caught in the earth's gravitational field will be pulled towards the center of the earth at a speed(velocity) of 9.8 meters per second and each second the speed will be accelerated by that much. So, that's how much speed is gained every second. Every second, you gain an addition to your speed of 9.8 meters per second until you reach "terminal velocity".

So, how do you fly? Not necessarily an easy task evidenced by the fact that man didn't start flying until about 200 years ago. The first flying was done with balloons.

So, let's look at how the balloon does it. Basically, it has to have a counteracting acceleration in the upwards direction. Or you could say, it needs something to pull it upwards. This is where buoyancy comes in. We already know why it wants to stay on the ground: gravity. But buoyancy allows us to counteract the force of gravity and take to the air.

So, we fill our balloon up with something that is lighter than air, like helium. Or we can simply heat the air. Hot air expands and weighs less than cold air. Let's just go with helium to make it as easy as possible here. So, the helium is lighter than air and we fill our balloon up with it. As we start filling the balloon the helium is taking up space where the air used to be.

You probably know that lighter things float. The reason that lighter things float is that gravity works both directions. The earth pulls on the water and air, but the air and water also pull on the earth. Air is less dense and has less pull because it has less mass. The water has more gravitational pull because it has more mass. So, the water will push the air out of the way as it seeks to travel to the center of the earth (and is stopped by the dirt that has even more mass and has already pushed the water out of the way as it seeks to move to the center of the earth). So, the lighter substances end up on top.

As we're filling up our balloon with helium, we're filling it up with a lighter gas that the air wants to push upwards. The air is heavier than the helium and so it tries to sink lower and push the helium upwards. Now just a little helium is not going to do it. You start filling the helium balloon and the helium pushes a certain volume of air to the sides as the helium goes into the space inside the balloon and the balloon starts to fill up. That lighter helium has an upward pull. (More accurately it's an upward push given to it by the air trying to fight it to fill up the space.) That is going to create an acceleration. At first it will not be enough to lift the balloon.

The amount of upwards push that the helium gives is directly proportional to the mass(weight) difference between the volume of helium in the balloon compared to the volume of air being pushed out of the way. The weight difference between the helium and air is what gives the buoyancy that pushes the balloon upwards and it increases by the volume of air displaced (pushed to the sides).

Eventually, the volume of air displaced (pushed to the sides) is more mass(weight) than the balloon itself. If the balloon weighs 1,000 kilograms (we use metric in physics), then it will begin to float off the ground about the time you get a mass(weight) difference between the helium vs. the air pushed aside of about 1,001 kilograms difference.

Once the balloon is "positively buoyant" (meaning it wants to float) it will have an upwards acceleration. Once the upwards acceleration of the buoyancy is greater than the downwards acceleration of gravity, the balloon will lift off the ground and head towards outer space.

The reason that the balloon never actually reaches outer space (assuming that it doesn't because some balloons actually do make it to the upper levels of the atmosphere which some consider "outer space") is the same reason that caused it to float in the first place. As you get higher into the atmosphere, the air becomes less dense, and so it's mass per volume is less. So, the helium gives less upwards force as the balloon gets higher into the atmosphere because the mass of the helium and mass of the air become more and more similar until the difference is not enough to overcome the mass of the balloon itself (basket, sand bags, passengers, etc.).

And that's basically buoyancy. A submarine works basically the same way. Water is pushed out of the submarine and the space filled with air. The difference between the water pushed out (displaced) and the air that replaced it causes the sub to float. Bring the water back on board and the sub will sink.

The other force that causes things to fly is "lift". Lift is caused by wings. Take an airplane for example. As the airplane is pushed forward by it's engines, the shape of the wing causes air to be pushed out of the way on one side of the wing (I've seen some arguments as to what actually happens here, but the fact that there is a difference on one side of the wing than the other side is all that matters.) So, the faster the plane moves, the more air that gathers on one side of the wing and the less air there is on the other. The difference in air volume on one side of the wing, as opposed to the other causes the wing to want to move to the area where there is less air similar to buoyancy. The wings are attached to the plane, and so the plane lifts into the air along with the wings.

Generally, the fast the plane moves the more "lift" that is generated and the greater the upwards acceleration counteracting gravity. A Cessna will overcome gravity very roughly somewhere around 120 miles per hour. If it ever stops moving forward at that speed it will fall like a rock.

So, basically to sum this novel up: buoyancy and lift counteract the acceleration of the earth's gravitational field. Perhaps, PhysX has a way of specifying those forces?
Was This Post Helpful? 1
  • +
  • -

#6 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 29 July 2013 - 06:03 AM

Hi BBeck.
Thank you for the thorough explanation about "flying".
I know understand what should actually happen with the object in my scene.
I don't have the PhysX documentation at hand at the moment since I'm at work but I'll definitely check it our if I can find the buoyancy thing and something that resembles the lift.

I hope that someone can reply to this so I know if this is possible since I'm quite a noob as it comes to PhysX.

I hope I can get a solution as fast as possible because I really need this. If nobody knows the "real" way of simulating this I'd be happy with a solution where you just restrain the object to the x and z axis.

Thanks again for all the effort you're putting into this.
Was This Post Helpful? 1
  • +
  • -

#7 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 29 July 2013 - 09:15 AM

You need to know this in terms of games where 90% of what has been explained is not calculated. In order to negate the effects of gravity you subtract the vector generated in the direction of the gravitational force. Note that buoyancy is not really directly related to gravity per se because there is the extra variable of a lifting force that can vary across the dimensions of the body to create the rocking motion of a boat on water for instance. Here we are purely speaking of gravity, where the force of gravity is dependant upon the velocity and masses of mutual objects.
Was This Post Helpful? 0
  • +
  • -

#8 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 29 July 2013 - 09:21 AM

SO you're saying. As long as I do
actorObject->addForce()
with the negative version of the gravity force I'm good?

Or is there more to it?
Was This Post Helpful? 0
  • +
  • -

#9 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 29 July 2013 - 12:43 PM

What do you think and why?
Was This Post Helpful? 0
  • +
  • -

#10 BBeck  Icon User is online

  • Here to help.
  • member icon


Reputation: 592
  • View blog
  • Posts: 1,321
  • Joined: 24-April 12

Re: PhysX Actor constrain movement flags.

Posted 29 July 2013 - 12:56 PM

View Postfrostraver, on 29 July 2013 - 11:21 AM, said:

SO you're saying. As long as I do
actorObject->addForce()
with the negative version of the gravity force I'm good?

Or is there more to it?



Can anyone get PhysX? I looked at NVidia's website and it says you have to register with them in one of about 6 different ways.

Is there a place where you can download the documentation? If I could look over the documentation, I might be able to make a suggestion. (I could theorize about how I would have programmed it, but all that really matters is how they programmed it. Not even to begin mentioning the other completely non-game programming projects I've got going on.)

I'm also kind of curious about PhysX now and would kind of like to play around with it. (As if I don't have enough completely random and unrelated game programming projects going simultaneously).

This post has been edited by BBeck: 29 July 2013 - 12:58 PM

Was This Post Helpful? 0
  • +
  • -

#11 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 29 July 2013 - 02:03 PM

I downloaded the installer through a website of my school. I can mail you a new link if you want.
I'll make a new upload of the package so you can work with it as well.

It should be free so I guess I can reupload it.

EDIT: Here's a link Download PhysX

EDIT: Forgot to reply to Butch. What I meant was "this is what you're suggesting right?". As in, I guess this is the right solution, this is what I would do like you suggested.

This post has been edited by frostraver: 29 July 2013 - 02:17 PM

Was This Post Helpful? 0
  • +
  • -

#12 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 29 July 2013 - 03:51 PM

View Postfrostraver, on 29 July 2013 - 06:03 PM, said:

EDIT: Forgot to reply to Butch. What I meant was "this is what you're suggesting right?". As in, I guess this is the right solution, this is what I would do like you suggested.

Getting there. You need to apply that force to a vector in the opposite direction to that of the vector representing the direction of the gravitational force.
Was This Post Helpful? 0
  • +
  • -

#13 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 29 July 2013 - 10:53 PM

Thanks for the quick reply Butch. I'm definitely going to try this out after work. I'll let you guys know if it worked out as I wanted to.

BBeck: Does the link work? If it doesn't, let me know and I'll fix it for you.
Was This Post Helpful? 0
  • +
  • -

#14 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 - 08:32 AM

Ok guys. So I tried with the following function
m_pTestPlayer->GetActor()->addForce(NxVec3(0, 50000000, 0));

It does do something and gives the object some lift but after a while it still comes down to the PhysX "ground". I did put this function in the update method of the engine (so this addForce is called every frame and this works).

I'll keep trying to find the magic number that is the force of the gravity in my scene otherwise I think I'll solve it differently and add some extra mechanics to the game
Was This Post Helpful? 0
  • +
  • -

#15 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 - 09:13 AM

No, don't add extra calculations. Work out why the gravity is 'reactivated' by debugging your code.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2