KamranK Posted May 14, 2018 Share Posted May 14, 2018 Hi, I am new to Babylon.js and trying out different things which I might need to use in future projects. I was wondering if there is a way to cancel out gravity from physics so the objects don't float away and stay static and just use the collision aspect of physics where the one mesh wont allow other meshes to pass through it. I found out that if I set the gravity to zero and the Impostor to PlaneImpostor the meshes stay static in space and I can move them around using pointerevents etc but the meshes dont have any interaction (meshes pass through each other when I drag them). I might have to add callbacks but that would be same as using collision detection without the physics engine Quote Link to comment Share on other sites More sharing options...
Guest Posted May 14, 2018 Share Posted May 14, 2018 Hello and welcome! To cancel gravity, just set mass to 0 Quote Link to comment Share on other sites More sharing options...
KamranK Posted May 15, 2018 Author Share Posted May 15, 2018 I did set mass to zero but the meshes still pass through each other when I drag them. They only interact when they have any mass Quote Link to comment Share on other sites More sharing options...
KamranK Posted May 15, 2018 Author Share Posted May 15, 2018 I guess what I require is not actually something that follows physics so its better to write collision detections Quote Link to comment Share on other sites More sharing options...
Guest Posted May 15, 2018 Share Posted May 15, 2018 Yeah you're right.Because the only way for you to have physics is to apply impulses and not moving the meshes directly Quote Link to comment Share on other sites More sharing options...
QuintusHegie Posted August 19, 2018 Share Posted August 19, 2018 (edited) Following up on this topic, is there a way to have the physics impostor working but not applying the gravity force on some meshes? For example, to simulate hoovering helicopter at fixed altitude or plane flying forward without falling? The option mesh.applyGravity=false Doesn't make a difference for the physics engine. When I use physicsImpostor.setMass(0) then the mesh doesn't respond to any force anymore and just sits there still, as if I ran the command physicsImpostor.sleep() same effect (all physics ignored, even applyImpulse and applyForce and setLineairVelocity etc.). In the desired scenario the steering of the helicopter and/or plane is done by application of force/impulse. And when two planes hit or plane hits helicopter then the physics engine will compute the new velocities and rotations for me. (For even more game excitement, when a rocket or missile hits the airborne unit ? ) Here's a picture to get the idea: The difference with a motorEnabled solution (for ground driving car like meshes) is that the plane or helicopter doesn't have a ground surface with friction to "roll up the wheels against". It is more like that the plane or helicopter motor/propeller cause upward force that compensate gravity. To lower altitude, the upward force on the object is lowered, and the gain altitude the upward force is increased relative to the gravity. Hope someone has some experience with physicEngine on this type of flying/floating meshes/gameobjects. ? Edited August 19, 2018 by QuintusHegie Added illustration Quote Link to comment Share on other sites More sharing options...
Raggar Posted August 19, 2018 Share Posted August 19, 2018 You have a few options to choose from. Every frame, you can set the Y velocity of the physics body to 0. You can also apply a constant upward force of the same value as the gravity. Or you can set the gravity to 0, and then apply downward forces to the bodies you need to apply gravity to. Another thing is to take the wanted position, let's say (14,20,32), and use this to calculate a direction vector based on the current position and the wanted position. Then you apply this vector as your force, to constantly keep the body moving toward the direction. The farther it is from the position, the faster it will go. That behavior can be prevented by scaling the vector by some static value, though. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 20, 2018 Share Posted August 20, 2018 @RaananW in case it would make a feature request ? RaananW 1 Quote Link to comment Share on other sites More sharing options...
QuintusHegie Posted August 20, 2018 Share Posted August 20, 2018 Hi Raggar, Thanks for your ideas. I like this suggestion the most as it keeps most steering options working forces intact for a flying/floating body: On 8/19/2018 at 10:52 PM, Raggar said: You can also apply a constant upward force of the same value as the gravity. I would then align this 'upward' applyForce vector with the direction of the propeller normal direction in world space. (see picture in my previous post) Player controls propeller speed and propeller rotation. More propeller power will then result in a higher factor to scale this vector with; lower propeller power lowers this steering factor and thus the downward gravity force slowly starts to win from the (local) updraft force of the drone. Also, when the propellers rotate 30 degrees around horizontal plane for example, the applied force to the main body will be both upward AND sideways hence making the drone fly forwards and some floating as well using the same steering mechanism. I'll try this approach and let you know if it solved the case. Take care, Q P.S. I'm also curious how Microsoft Flight Arcade http://flightarcade.com/ computed the plane vectors and forces; must have been similar challenge I guess... ? Sebavan 1 Quote Link to comment Share on other sites More sharing options...
QuintusHegie Posted August 22, 2018 Share Posted August 22, 2018 Short update. To float or hoover a plane/drone/ufo it works to apply a force on every scene render that negates the gravity force by some factor (e.g. 1 for perfect hoover) dronemesh.physicsImpostor.applyForce( scene.getPhysicsEngine().gravity.negate().scaleInPlace(damping_factor * speed_throttle), dronemesh.physicsImpostor.getObjectCenter()); The damping factor adjusts the speed throttle of the drone (gamepad axis) so that I can setup different drone lifting power (e.g. drones with bigger or smaller propellers). When you translate the drone local normal vector by some angle around an axis, then you can add forces to the x and z direction as well in order to steer the drone sideways and backward/forward. I haven't worked out those computations at this moment though, because I first wanted to test if I can make a drone mesh float in air by simulation upward propeller force. ? Q DylanD 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.