Jump to content

Vehicle WIP in Leadwerks 4.6

Josh

1,052 views

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


16 Comments


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.
Vehicle.h
Vehicle.cpp

  • 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.

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.

×
×
  • Create New...