Jump to content

New Physics Features in Leadwerks 4.4

Josh

2,349 views

Leadwerks Game Engine 4.4 features an upgrade to the latest version of Newton Dynamics, along with a bunch of new features to enhance physics.

Kinematic Controller
The new kinematic controller is a joint that lets you specify a position, rotation (Euler or quaternion), or a 4x4 matrix to orient the body to.  You can set the maximum linear and angular force the joint may use to orient the entity.  This allows you to create a kinematic controller that only affects position, only affects rotation, or one that controls both at once.  In the video below I am using a kinematic controller to create a simple IK system with two hinge joints.  The end effector is controlled by the mouse position, while the base entity stays in place, since it has zero (infinite) mass:

The kinematic controller provides much more stable collisions than the Entity PhysicsSetPosition() and PhysicsSetRotation() commands, and should be used in place of these.  In fact, these commands will be removed from the documentation and should not be used anymore, although they will be left in the engine to ensure your code continues to work.  The FPS player script will be updated to use a kinematic control for objects you are holding, which will eliminate the energetic collisions the script currently produces if you pick up a crate and push it into the wall.

The new joint commands are as follows:

static Joint* Kinematic(Entity* entity, const Vec3& position);
virtual void SetTargetMatrix(const Mat4& mat);
virtual void SetTargetPosition(const float x, const float y, const float z, const float blend = 0.5);
virtual void SetTargetPosition(const Vec3& pos, const float blend = 0.5);
virtual void SetTargetRotation(const float pitch, const float yaw, const float roll, const float blend = 0.5);
virtual void SetTargetRotation(const Vec3& rotation, const float blend = 0.5);
virtual void SetTargetRotation(const Quat& rotation, const float blend = 0.5);

For improved constistency in the API, the joint SetAngle function will be renamed SetTargetAngle, but a copy of the old command will remain in the engine:

virtual void SetTargetAngle(const float angle);

Joint Friction
Hinge joints can now accept a friction value to make them more resistant to swinging around.  I used this in the example below to make the joints less "loose", while a kinematic controller positions the green box:

New Vehicle Model
Newton 3.14 features a new vehicle model with a realistic simulation of a slip differential.  Power is adjusted to each wheel according to the resistance on each tire.

17634312_10154987760341183_2545546855562571217_n.png.e07fcedc55d8782cb027516383cf8f0f.png

Watch closely as the wheels below act just like a real car does when its tires slip:

The realistic vehicle models gives vehicles a much more visceral and fun feeling.  The new vehicle also uses actual bodies for the tires, instead of convex raycasts, so the sudden bouncing the old vehicles could exhibit if the chassis didn't encompass the tires is eliminated.

Springs

Slider and hinge joints now have optional spring behavior you can enable with one command.  Use this to make our own custom suspension system, or anything else you need.

void SetSpring(const float spring)

These changes will be available next week on the beta branch on Steam.



13 Comments


Recommended Comments

Woaw this looks sweet ! 

Is it not possible to keep PhysicsSetPosition() and PhysicsSetRotation() commands and internally call the new SetTargetPosition() and SetTargetRotation() by creating a default Kinematic joint when called the first time ?

Share this comment


Link to comment
56 minutes ago, Wchris said:

Woaw this looks sweet ! 

Is it not possible to keep PhysicsSetPosition() and PhysicsSetRotation() commands and internally call the new SetTargetPosition() and SetTargetRotation() by creating a default Kinematic joint when called the first time ?

It would produce different (better) behavior, and I don't want to manage a secret joint.

Share this comment


Link to comment
10 hours ago, Josh said:

It would produce different (better) behavior, and I don't want to manage a secret joint.

Your choice. Just suggesting. 

But there could be a global parameter to set PhysicsSetPosition() and PhysicsSetRotation() behavior/mode

Is "managing secret things" not what game engines do all the time ? LOL

I just have the feeling that creating joints is an advanced feature that could look difficult to understand for beginners. Maybe I'm wrong.

Don't do it just for me, it's just an idea, not a request.

Share this comment


Link to comment
8 hours ago, Wchris said:

Your choice. Just suggesting. 

But there could be a global parameter to set PhysicsSetPosition() and PhysicsSetRotation() behavior/mode

Is "managing secret things" not what game engines do all the time ? LOL

I just have the feeling that creating joints is an advanced feature that could look difficult to understand for beginners. Maybe I'm wrong.

Don't do it just for me, it's just an idea, not a request.

The way the new joint works is you set the desired orientation once, and it holds it.  The PhysicsSetPosition() command has to be continually called each frame, or the object stops being positioned.

And again, there might be people depending on the current behavior of those commands, and changing them would break their game.

Share this comment


Link to comment
39 minutes ago, nick.ace said:

Is it possible to increase the joint elasticity? Or does friction do this?

Sliders and hinges can now act as springs.

Share this comment


Link to comment

I can't get my vehicle to reach a decent speed as it starts to bounce, am I ignoring any settings for the tires?
 

Share this comment


Link to comment
1 hour ago, Yue said:

I can't get my vehicle to reach a decent speed as it starts to bounce, am I ignoring any settings for the tires?
 

No. There are additional parameters for spring damping that I need to expose to give you more control.

  • Sad 1

Share this comment


Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Blog Entries

    • By jen in jen's Blog 3
      I thought I would share my experience on this; if you're working on Multiplayer, you will need to protect your packets. The solution is simple, let's go through how we can achieve this by implementing what Valve calls "challenge codes". (Some reading on the topic from Valve here: https://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol#Challenge_response).
      Disclaimer: this doesn't cover other security techniques like authoritative server or encryption.
      So, I've worked on Border Recon last year (I think) and I needed a way to protect my server/client packets. There was no need for me to re-invent the wheel, I just had to copy what Valve has had for a  long time - challenge  codes.
      The idea behind challenge codes is similar to Captcha, but not exactly. Think of it like this: for every packet submitted to the server, it must be verified - how? By requiring the client to solve challenges our server provides.
      To implement this we need to have the following:
      A randomised formula in the server i.e.: a = b * c / d + e or a = b / c + d - e, be creative - it can be any combination of basic arithmetic or some fancy logic you like and can be however long as you want - do consider that the longer the formula, the more work your server has to do to make the computation.  Copy the same formula to the client. A random number generator.  So the idea here is:
      (Server) Generate a random number (see 3 above) of which the result would become the challenge code, (Server) run it through our formula and record the result. (Client) And then, we hand over the challenge code to the client to solve (an authentic client would have the same formula implemented in its program as we have on the server). For every packet received from the player, a new challenge code is created (and the player is notified of this change by the server in response). For every other packet, a new challenge code is created. (Client) Every packet sent to the server by the client must have a challenge code and its answer embedded.  (Server receives the packet) Run the challenge code again to our formula and compare the result to the answer embedded on the client's packet. (Server) If the answers are different, reject the packet, no changes to the player's state. The advantage(s) of this strategy in terms of achieving the protection we need to secure our server:
      - For every packet sent, new challenge code is created. Typically, game clients (especially FPS) will update its state in a matter of ms so even if a cheater is successful at sniffing the answer to a challenge code it would be invalidated almost instantaneously. 
      - Lightweight solution. No encryption needed. 
      Disadvantage(s):
      - The formula to answering the challenge code is embedded to the client, a cheater can de-compile the client and uncover the formula. Luckily, we have other anti-cheat solutions for that; you can implement another anti-cheat solution i.e. checking file checksums to verify the integrity of your game files and more (there are third-party anti cheat solutions out there that you can use to protect your game files).
       
       
       
    • By Josh in Josh's Dev Blog 4
      New commands in Turbo Engine will add better support for multiple monitors. The new Display class lets you iterate through all your monitors:
      for (int n = 0; n < CountDisplays(); ++n) { auto display = GetDisplay(n); Print(display->GetPosition()); //monitor XY coordinates Print(display->GetSize()); //monitor size Print(display->GetScale()); //DPI scaling } The CreateWindow() function now takes a parameter for the monitor to create the window on / relative to.
      auto display = GetDisplay(0); Vec2 scale = display->GetScale(); auto window = CreateWindow(display, "My Game", 0, 0, 1280.0 * scale.x, 720.0 * scale.y, WINDOW_TITLEBAR | WINDOW_RESIZABLE); The WINDOW_CENTER style can be used to center the window on one display.
      You can use GetDisplay(DISPLAY_PRIMARY) to retrieve the main display. This will be the same as GetDisplay(0) on systems with only one monitor.
    • By Josh in Josh's Dev Blog 1
      A huge update is available for Turbo Engine Beta.
      Hardware tessellation adds geometric detail to your models and smooths out sharp corners. The new terrain system is live, with fast performance, displacement, and support for up to 255 material layers. Plugins are now working, with sample code for loading MD3 models and VTF textures. Shader families eliminate the need to specify a lot of different shaders in a material file. Support for multiple monitors and better control of DPI scaling. Notes:
      Terrain currently has cracks between LOD stages, as I have not yet decided how I want to handle this. Tessellation has some "shimmering" effects at some resolutions. Terrain may display a wire grid on parts. Directional lights are supported but cast no shadows. Tested in Nvidia and AMD, did not test on Intel. Subscribers can get the latest beta in the private forum here.

       
       
×
×
  • Create New...