Jump to content

Vehicle WIP in Leadwerks 4.6



Here's a look at the new vehicle system that is being developed. The API has been simplified so you simply create a vehicle, add as many tires as you want, and start using it. The AddTire() command now accepts a model and the dimensions of the tire are calculated from the bounds of the mesh.

class Vehicle
	int AddTire(Model* model, bool steering=false, const float spring=500.0f, const float springrelaxation = 0.1f, const float springdamping = 10.0f);
	void SetGas(const float accel);
	void SetBrakes(const float brakes);
	void SetSteering(const float angle);
	static Vehicle* Create(Entity* entity);

A script will be provided which turns any vehicle model into a ready-to-use playable vehicle. The script searches for limb names that start with "wheel" or "tire" and turns those limbs into wheels. If they are positioned towards the front of the car, the script assumes the wheels can be turned with steering. You can also reverse the orientation of the vehicle if the model was designed backwards.

There is one big issue to solve still. When a vehicle drives on flat terrain the tires catch on the edges of the terrain triangles and the whole vehicle bounces around badly. I'm looking into how this can be solved with custom collision overrides. I do not know how long this will take, so it might or might not be ready by Christmas.

  • Like 3
  • Thanks 1


Recommended Comments

That video looks pretty solid.  I assume we create our own collision mesh(es) for the body?  For example, a car. a truck and a plough truck will have different looking meshes.

It would also be nice if the code that detects "wheel" and "tire" could also detect the words "front," "back," "left" and "right" in the names.  That way there would be no ambiguity and we can name a tire tire.front.left or FrontLeftWheel, for example.

Also, what do you mean by a script doing the interpretation?  How do people using only C++ get their car tires detected?

Share this comment

Link to comment

Yes, you can have your own physics shape for the chassis. In fact you can also now have your own physics shapes for the wheels.

A search for the term "wheel" will return a false positive if a limb called "steeringwheel" is encountered. Perhaps if the name contains "tire" or if the left five characters are "wheel" or if the name contains "wheel" AND does not contain "steer"?

It's easiest to just throw a script on a model, but a C++ example will also be provided.

Share this comment

Link to comment

Yeah, the rules seem pretty easy to set up and probably best to search for minimal terms, not combined terms.  If the name contains "steering" then it's safe to assume it's a steering wheel.  Name could also be "steering wheel" or "steering_wheel" so searching for "steeringwheel" might not work.  Though it's not too bad to ask devs to name limbs specific things (like how we have collisionhull right now), it's ideal to be flexible, if possible, to not even need to have devs alter their models.

Also, the model could include a spare tire on the back (or in the trunk), like Jeeps do (https://ddcfq0gxiontw.cloudfront.net/Review/39832078/17545495/medium_square.jpg) so not sure how you'd handle that.  I guess if the name includes "spare," it's disregarded.

Share this comment

Link to comment

This looks great.

But I have to ask: It would have been so interesting for me (and maybe others) to know the issue on how to get a solid car when using the joints system a few members here worked on for a few months.. ;) !! Could/is this now be possible ? 

Share this comment

Link to comment
1 hour ago, Jorns2 said:

So, that can be used for tanks ? and wil be avaiable for .lua?

You could make a tank with this using lots of wheels. I am not making a tread system right now, but that is possible simply by using the hinge joint:

32 minutes ago, Marcousik said:

This looks great.

But I have to ask: It would have been so interesting for me (and maybe others) to know the issue on how to get a solid car when using the joints system a few members here worked on for a few months.. ;) !! Could/is this now be possible ? 

Here is the source for the vehicle class. It just uses regular joints. There is one tricky part I have to customize though so the wheel collision is better at high speeds.

  • Confused 1

Share this comment

Link to comment

Here's another look at the physics. It looks very good but there are a couple of problems to work out still:


  • Like 1
  • Thanks 1

Share this comment

Link to comment

Okay great. Did you manage to use SetString() or slider joint() for the suspension ?

I could not find anything running ok with SetString() (well with 4.5)

The climb effect looks very nice, I think better than simple joints let do. how did you manage this ? Any tipps 😉



Share this comment

Link to comment

What does SetString have to do with vehicles?

i turned the friction way up on the tires. The climbing behavior is actually pretty realistic. A real 4x4 will do that, although the impact when it hit the hill probably would have ripped the wheels off

Share this comment

Link to comment

@Josh  "What does SetString have to do with vehicles?"

Well you recommended  to use SetSpring() for vehicles suspensions in Juli instead of enabling the slider joints limit. 

I wanted to know if you disable the limit on the suspension and use SetSpring() in 4.6 ?

Share this comment

Link to comment

SetSpring() not SetString() ;)

I am experimenting with the joint limit. It works about the same either way.

Share this comment

Link to comment

Okay yes, sure..little confusion.

Something more:

Do I have to replace the vehicles.h with the one you upload here ?

What should I do with the .cpp file? 

Can I use this with lua ? Im a newbie to this sorry




Share this comment

Link to comment

Actually it helps me a lot because I try toread the c++ functions. I'm  actually wondering what is "mat" used for ?

Vec3 scale = entity->mat.GetScale();

Then it becames mat[1], mat[2] and mat[3] but I can't find the definition of this.

Can't find where does this "mat" comes out...



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.

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 Josh in Josh's Dev Blog 7
      You might have seen this graphic comparing the size of the world in different games. I've played Fuel, and never reached the end of the world in that game. You can drive for a very long time on those roads.

      We want to use the new engine for realistic simulations of air and ground movements. At normal cruising altitude of a commercial airliner, the pilot has a view range of about 400 kilometers. The image below shows that area (800 x 800 km). You can see the areas of the biggest games ever fit neatly into the corner of just our visible area.

      The gray space above is not the total world size, it is just the area you can see at once from high altitude. The total world size is about 50 times bigger.
      This is what I am working on now.
    • By Josh in Josh's Dev Blog 26
      Gamers have always been fascinated with the idea of endless areas to roam.  It seems we are always artificially constrained within a small area to play in, and the possibility of an entire world outside those bounds is tantalizing.  The game FUEL captured this idea by presenting the player with an enormous world that took hours to drive across:
      In the past, I always implemented terrain with one big heightmap texture, which had a fixed size like 1024x1024, 2048x2048, etc.  However, our vegetation system, featured in the book Game Engine Gems 3, required a different approach.  There was far too many instances of grass, trees, and rocks to store them all in memory, and I wanted to do something really radical.  The solution was to create an algorithm that could instantly calculate all the vegetation instances in a given area.  The algorithm would always produce the same result, but the actual data would never be saved, it was just retrieved in the area where you needed it, when you needed it.  So with a few modifications, our vegetation system is already set up to generate infinite instances far into the distance.

      However, terrain is problematic.  Just because an area is too far away to see doesn't mean it should stop existing.  If we don't store the terrain in memory then how do we prevent far away objects from falling into the ground?  I don't like the idea of disabling far away physics because it makes things very complex for the end user.  There are definitely some tricks we can add like not updating far away AI agents, but I want everything to just work by default, to the best of my ability.
      It was during the development of the vegetation system that I realized the MISSING PIECE to this puzzle.  The secret is in the way collision works with vegetation.  When any object moves all the collidable vegetation instances around it are retrieved and collision is performed on this fetched data.  We can do the exact same thing with terrain   Imagine a log rolling across the terrain.  We could use an algorithm to generate all the triangles it potentially could collide with, like in the image below.

      You can probably imagine how it would be easy to lay out an infinite grid of flat squares around the player, wherever he is standing in the world.

      What if we only save heightmap data for the squares the user modifies in the editor?  They can't possibly modify the entire universe, so let's just save their changes and make the default terrain flat.  It won't be very interesting, but it will work, right?
      What if instead of being flat by default, there was a function we had that would procedurally calculate the terrain height at any point?  The input would be the XZ position in the world and the output would be a heightmap value.

      If we used this, then we would have an entire procedurally generated terrain combined with parts that the developer modifies by hand with the terrain tools.  Only the hand-modified parts would have to be saved to a series of files that could be named "mapname_x_x.patch", i.e. "magickingdom_54_72.patch".  These patches could be loaded from disk as needed, and deleted from memory when no longer in use.
      The real magic would be in developing an algorithm that could quickly generate a height value given an XZ position.  A random seed could be introduced to allow us to create an endless variety of procedural landscapes to explore.  Perhaps a large brush could even be used to assign characteristics to an entire region like "mountainy", "plains", etc.
      The possibilities of what we can do in Leadwerks Engine 5 are intriguing.  Granted I don't have all the answers right now, but implementing a system like this would be a major step forward that unlocks an enormous world to explore.  What do you think?

    • By Haydenmango in Snowboarding Development Blog 6
      So I've been researching snowboarding lately to get an idea of what animations and mechanics I need to create for my game.  I have learned lots of interesting things since I've only seen snow once or twice in my entire life and have never even tried snowboarding or any other board sports (skateboarding, surfing, etc.) for that matter.
      Snowboarding tricks are quite interesting as they are mostly derived from skateboarding.  Snowboarding tricks pay homage to their equivalent skating tricks by sharing many concepts and names.  For example basic grabs in snowboarding share the same concepts and names as skateboarding: indy, mute, method, stalefish, nosegrab, and tailgrab.  Something interesting to note is in snowboarding you can grab Tindy or Tailfish but this is considered poor form since these grabs can't be done on a skateboard (due to the board not being attached to the skaters feet) and grabbing these areas is generally something a novice snowboarder does when failing or "half-assing" a normal grab.  Check out this diagram to see how grabs work -
      So, after reading lots of text descriptions for tricks I was still confused by what all these terms meant and how they were actually applied.  So my next step was to look up these tricks actually being done and I found some really cool videos showing off how to do various tricks.  This video in particular is the best reference material I've found as it contains nearly every trick back to back with labeled names and some tweaks -
      Sadly my rigged model doesn't handle leg animations with the snowboard that well so I can't animate as many tricks as I want to.  Regardless there will still be around 15 total grab/air tricks in the game.  Now it's time for me to stop procrastinating and start animating!  
  • Create New...