Jump to content
  • entries
    39
  • comments
    81
  • views
    12,002

Smoothed car drive - Leadwerks 4.5


Marcousik

3,519 views

 Share

I'm just happy to get this work :) here is a demo:

This is actually better than driving in 4.3 because cars are now  able to jump or crash without experimenting crazy rotations or whatever  ?

 

 

Here is the script to make this:

 

> Here the values I used:

 

2018-07-12.thumb.png.f462ba4098f0a5614444063419c79949.png

 

 

> And here what changed: Is written in dark:

-------------------------------------

function Script:Start()

-- [...........]

-- Construit les amortisseurs: / suspensions
local n
local pos
    for n=0,3 do
        pos=self.entity:GetPosition(true)
        self.Axes[n]:SetMass(self.TireMass)
        self.Amortisseurs[n]=Joint:Slider(pos.x, pos.y, pos.z, 0,1,0, self.Axes[n], self.entity)

        self.Amortisseurs[n]:EnableLimits()
        self.Amortisseurs[n]:SetLimits(-0.25/2,0.25/2)

        self.Amortisseurs[n]:SetTargetAngle(-self.Amort)    --at the middle if 0
        self.Amortisseurs[n]:SetMotorSpeed(10000)    ------------- vitesse de la pompe/ suspensions speed
        self.Amortisseurs[n]:SetStrength(self.Force)    --defatul is 1000
        self.Amortisseurs[n]:EnableMotor()    

    end

-- [...........]     

 

-----  I removed the backward suspensions with 2* forces because this only depends on the positions of the suspensions on the chassis.

----- Making them symmetrical is ok to solve this.

 

----------------------------------------
function Script:UpdatePhysics()


if self.MyCar==1 and InCar>0 then

    
-- Traite la direction:    
local turning=0
    local direction=self.Volants[0]:GetAngle()

    if window:KeyDown(Key.Left) then
        direction=direction-5 turning=-1
    elseif window:KeyDown(Key.Right) then
        direction=direction+5 turning=1
    elseif window:KeyDown(Key.Left)==false and window:KeyDown(Key.Right)== false then 
        if Math:Round(direction)>0 then direction=direction-5
        elseif Math:Round(direction)<0 then direction=direction+5
        end
    end
    self.Volants[0]:SetAngle(direction)
    self.Volants[1]:SetAngle(direction)

-- Traite l'acceleration:

local Gas=0
        if window:KeyDown(Key.Up) then
            Gas=1
            self.currspeed = self.currspeed + 10
            if self.currspeed>self.SpeedMax then
                self.currspeed=self.SpeedMax
            end
        
        elseif window:KeyDown(Key.Down) then
            Gas=-1
            self.currspeed = self.currspeed - 10
            if self.currspeed<-self.SpeedMax then
                self.currspeed=-self.SpeedMax
            end
        end

        if Gas==0 then  self.currspeed=0
            for n=0,3 do
            self.Rouages[n]:DisableMotor()
            end
        else
            for n=0,3 do
            if self.Rouages[n]:MotorEnabled()==false then self.Rouages[n]:EnableMotor() end
            self.Rouages[n]:SetTargetAngle(self.Rouages[n]:GetAngle()+1000)

            self.Rouages[n]:SetMotorSpeed(self.currspeed)
            self.Tires[n]:SetOmega(self.Tires[n]:GetOmega()*Vec3(5,5,5))   ---------  make the car go faster
            end
        end

--Smoothing:

if turning==0 then
    self.entity:SetOmega(self.entity:GetOmega()*Vec3(-1,-1,-1))
else self.entity:SetOmega(0,turning*Gas,0) end

    self.Axes[0]:SetOmega(self.Axes[0]:GetOmega()*Vec3(-1,-1,-1))
    self.Axes[1]:SetOmega(self.Axes[1]:GetOmega()*Vec3(-1,-1,-1))
    self.Axes[2]:SetOmega(self.Axes[2]:GetOmega()*Vec3(-1,-1,-1))
    self.Axes[3]:SetOmega(self.Axes[3]:GetOmega()*Vec3(-1,-1,-1))

    self.Axes[0]:SetVelocity(self.Axes[0]:GetVelocity()*Vec3(1,0.5,1))
    self.Axes[1]:SetVelocity(self.Axes[1]:GetVelocity()*Vec3(1,0.5,1))
    self.Axes[2]:SetVelocity(self.Axes[2]:GetVelocity()*Vec3(1,0.5,1))
    self.Axes[3]:SetVelocity(self.Axes[3]:GetVelocity()*Vec3(1,0.5,1))


-- fake wheels update:
    
        self.Wheels[0]:SetMatrix(self.Tires[0]:GetMatrix())
        self.Wheels[1]:SetMatrix(self.Tires[1]:GetMatrix())
        self.Wheels[2]:SetMatrix(self.Tires[2]:GetMatrix())
        self.Wheels[3]:SetMatrix(self.Tires[3]:GetMatrix())

        self.Wheels[0]:SetPosition(self.PosWheels[0]+Vec3(0,self.Amortisseurs[0]:GetAngle()/6,0))
        self.Wheels[1]:SetPosition(self.PosWheels[1]+Vec3(0,self.Amortisseurs[1]:GetAngle()/6,0))
        self.Wheels[2]:SetPosition(self.PosWheels[2]+Vec3(0,self.Amortisseurs[2]:GetAngle()/6,0))
        self.Wheels[3]:SetPosition(self.PosWheels[3]+Vec3(0,self.Amortisseurs[3]:GetAngle()/6,0))
end

 

  • Like 1
 Share

12 Comments


Recommended Comments

Listen to a question, how is it possible that you climb steep hills, in my case the car doesn't get in, it runs out of strength.

Link to comment
24 minutes ago, Yue said:

Listen to a question, how is it possible that you climb steep hills, in my case the car doesn't get in, it runs out of strength.

You probably need to adjust the wheel speed to not go so fast. This is the hardest part. If you just use a constant wheel speed it will be either too overpowered or too weak.

  • Like 1
Link to comment

The question is how realistic should that be, well making a monster truck is sure a challenge ?

Normal cars doesn't have to climb to much or just make a soft road like 10-15 slope rotation.

This car climbs a 20% road .. Just check the friction(5,5) on the tires! Maybe for a monster truck should the tires be bigger ? (not tested)

 

  • Like 1
Link to comment

I understand that the slope goes up with enough momentum, however if you stop on a slope like that, you will most likely not go up. Then I thought about the gears of a car and the question is how realistic is the question 

Link to comment

I have a problem, when I want to put the tires in the respective place of the chassis of my vehicle, the car starts to jump like crazy. Any suggestions? 

 

image.png.278a08d7bd3f1c31306567218d81123c.png

Link to comment
6 minutes ago, Josh said:

Maybe the chassis is hitting the tires?

 

If that seems to be the case, there are some commands to disable the tires from colliding with the chassis? any suggestions are welcome. 

image.thumb.png.a727710c9e37b3454eab4de2255a0f17.pngdfsdf

 

Link to comment

Hey Yue,

I did this to avoid this problem for sure:

set the chassis collision type to "character" and set the tires to collision type "debris". Because there is no collision between character and debris.

You have to control the mass of the tires and chassis too: big chassis mass + little tires mass = crazy jumping.

I would not fix the tires directly on your "MontaCargas", instead of this fix them on a simple box (that you have to create, just as big as your model is) and set the MontaCargas als child, just as a decoration object with no shape.

If the simple box becomes drivable, you can add whatever you want as "deco" model... Set then the box a invisible material to hide it. 

It is maybe fake... but it runs ;) 

  • Thanks 1
Link to comment

Thank you, the problem has been solved, undoubtedly something new to learn about "Debris" that translates into Spanish as rubble, very small things. 

Thank you very much. 

image.png.5b6f9aef5b1551350d23cc71ffa0d1a6.png

Link to comment
self.Tires[n]:SetOmega(self.Tires[n]:GetOmega()*Vec3(5,5,5))   ---------  make the car go faster

very smart!

--Smoothing:

if turning==0 then
    self.entity:SetOmega(self.entity:GetOmega()*Vec3(-1,-1,-1))
else self.entity:SetOmega(0,turning*Gas,0) end

    self.Axes[0]:SetOmega(self.Axes[0]:GetOmega()*Vec3(-1,-1,-1))
    self.Axes[1]:SetOmega(self.Axes[1]:GetOmega()*Vec3(-1,-1,-1))
    self.Axes[2]:SetOmega(self.Axes[2]:GetOmega()*Vec3(-1,-1,-1))
    self.Axes[3]:SetOmega(self.Axes[3]:GetOmega()*Vec3(-1,-1,-1))

    self.Axes[0]:SetVelocity(self.Axes[0]:GetVelocity()*Vec3(1,0.5,1))
    self.Axes[1]:SetVelocity(self.Axes[1]:GetVelocity()*Vec3(1,0.5,1))
    self.Axes[2]:SetVelocity(self.Axes[2]:GetVelocity()*Vec3(1,0.5,1))
    self.Axes[3]:SetVelocity(self.Axes[3]:GetVelocity()*Vec3(1,0.5,1))


-- fake wheels update:
    
        self.Wheels[0]:SetMatrix(self.Tires[0]:GetMatrix())
        self.Wheels[1]:SetMatrix(self.Tires[1]:GetMatrix())
        self.Wheels[2]:SetMatrix(self.Tires[2]:GetMatrix())
        self.Wheels[3]:SetMatrix(self.Tires[3]:GetMatrix())

        self.Wheels[0]:SetPosition(self.PosWheels[0]+Vec3(0,self.Amortisseurs[0]:GetAngle()/6,0))
        self.Wheels[1]:SetPosition(self.PosWheels[1]+Vec3(0,self.Amortisseurs[1]:GetAngle()/6,0))
        self.Wheels[2]:SetPosition(self.PosWheels[2]+Vec3(0,self.Amortisseurs[2]:GetAngle()/6,0))
        self.Wheels[3]:SetPosition(self.PosWheels[3]+Vec3(0,self.Amortisseurs[3]:GetAngle()/6,0))
end

too much tuning on all of this constants... very nice!

  • Like 1
Link to comment

i do like the way the cars behave at low speed with leadwerks physics, but, as speed rises it shakes so much, so for omega i was using something like:

self.entity:SetOmega(omega.x/(1+2*currentSpeed/maxSpeed),omega.y/(1+currentSpeed/maxSpeed),omega.z/(1+2*currentSpeed/maxSpeed))

this way, i use the omega practically unaltered at low speed and then as speed rises and goes near maxSpeed, the x,y,z components are modulated

playing with the 1+2* or 1+1* or 1+5* i get more or less attenuation on desired axes.

I do not play with your car, stiil, I will for sure, in the video it looks and behaves very well, but so much rigid at low speed (for me )

the x5 is still in my mind.. will try, thank´s for sharing all this stuff

Link to comment

thx for sharing your ideas too 

I'm not sure about SetOmega how it works....

> I first thought SetOmega(..., false) would be what I need as the tires are children... But I could not get anything regular..?‍♀️

> Then I thought SetOmega(0,0,0) should be the best I want to drop down the crazy shaking rotations.

> Then I found that 

self.entity:SetOmega(self.entity:GetOmega()*Vec3(-1,-1,-1))

is a little bit better. As it throws an inverted force to the angle velocity.

> I think *Vec3(-5,-5,-5)) would make the shaking forces same (or more?) but just inverted, not tested I just did not try but maybe it works ??

 

It's fascinating to make several 100 of tests to understand how the engines works... There is much to learn from Docu and forum and so much remains to test how the engine answers.

 

 

 

Link to comment
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...