Jump to content

working car physics


diedir
 Share

Recommended Posts

Hi all

i am trying to make "setkey("friction") working but from 0.0 to 1.0, no obvious change seems appear.

 

do we must tweak the chassis or each tire ?

no luck on both.

 

i tried then "object.tire:SetFriction" as seen in the train-trucks scripts don't work at all (give error) works only with chassis

i set it in the main lua script of my car.

 

here my code:

 

require("scripts/class")
require("scripts/loop")
require("scripts/math/math")

local class=CreateClass(...)

function class:CreateObject(model)
       local object=self.super:CreateObject(model)

       function object:UpdateMatrix()
               self:UpdateTires()
       end

       function object:UpdateTires()
               local speed
               for n=0,3 do
                       if self.tire[n]~=nil then
                               self.tire[n]:SetMatrix( self.vehicle:GetTireMatrix(n) )
                               if self.emitter[n]~=nil then
                                       self.emitter[n]:SetMatrix(self.vehicle:GetTireMatrix(n))
                                       self.emitter[n]:Pause()
                                       if self.vehicle:TireIsAirborne(n)==0 then
                                               speed = math.abs(self.model:GetVelocity(0).z)
                                               speed = (speed - 4) * 20.0	--20
                                               speed = Clamp( speed, 0, 1 ) * 0.5
                                               if speed>0.2 then -->0
                                                       self.emitter[n]:Resume()
                                                       self.emitter[n]:SetColorf(1,1,1,speed)
                                               end
                                       end
                               end
                       end
               end
       end

	local couronne
       local pivot
       local suspensionlength=0.2	--0.1
       local springconstant=50	--25
       local springdamper=200	--115

	object.vehicle=CreateVehicle(object.model)
       object.model:SetMass(2.2)	
	object.model:SetFriction(0.4,0.3)
	object.model:SetKey("Gravity",1)

       object.tire={}
       object.emitter={}

	pivot=object.model:FindChild("roueavantg")
        if pivot~=nil then

                tireradius=pivot.aabb.h/2.0
                object.vehicle:AddTire(TFormPoint(pivot.position,pivot.parent,model),tireradius,suspensionlength,springconstant,springdamper)
                object.tire[0]=LoadMesh("abstract::lp_roueavtg.gmf",object.model)
                pivot:Hide()

        end

        pivot=object.model:FindChild("roueavantd")
        if pivot~=nil then
                tireradius=pivot.aabb.h/2.0
                object.vehicle:AddTire(TFormPoint(pivot.position,pivot.parent,model),tireradius,suspensionlength,springconstant,springdamper)
                object.tire[1]=LoadMesh("abstract::lp_roueavtd.gmf",object.model)
                pivot:Hide()

        end     

        pivot=object.model:FindChild("rouearg")
        if pivot~=nil then
                tireradius=pivot.aabb.h/2.0
                object.vehicle:AddTire(TFormPoint(pivot.position,pivot.parent,model),tireradius,suspensionlength,springconstant,springdamper)
                object.tire[2]=LoadMesh("abstract::lp_rouearg.gmf",object.model)
                pivot:Hide()
        end

        pivot=object.model:FindChild("roueard")
        if pivot~=nil then
                tireradius=pivot.aabb.h/2.0
                object.vehicle:AddTire(TFormPoint(pivot.position,pivot.parent,model),tireradius,suspensionlength,springconstant,springdamper)
                object.tire[3]=LoadMesh("abstract::lp_roueard.gmf",object.model)
                pivot:Hide()
        end     


       object.emitter={}
       object:UpdateTires()


               if fw~=nil then
                       SetWorld(fw.transparency.world)
                       for n=0,3 do
                               if object.tire[n]~=nil then --createemitter(50,2000,Vec3...
                                       object.emitter[n]=CreateEmitter(5,2000,Vec3(0,1,0),0,object.tire[n])
                                       object.emitter[n]:SetPosition(Vec3(0,-object.tire[n].aabb.h/2.0,0))
                                       object.emitter[n]:SetParent(model,1)
                                       object.emitter[n]:SetRadius(0,4) --1.6
                                       object.emitter[n]:SetWaver(0.2) --1.0
                                       object.emitter[n]:Paint(LoadMaterial("abstract::roaddust.mat"))
                                       object.emitter[n]:SetRotationSpeed(0.1)
                                       object.emitter[n]:Pause()
                               end
                       end
                       SetWorld(fw.main.world)
               end		

       object.model.buoyant=0
       object.model:SetKey("collisiontype",COLLISION_PROP)
       object:UpdateTires()
end

 

if someone could post a working exemple of friction applied.

thank you

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

thank you Aggror for answering

 

no i didn't try "self.tire" but i will thanks

 

for the friction i thought it was a float between 0 to 1 but i'm a bit lost with lua commands

because nothing is clear for this language in wiki, not much examples,

but i am playing around with code and sometimes the sky is brighter...

 

i asking me if joints are harder to apply but better (in performance) than an animated mesh, your (or anyone) advice would be great.

 

by the way, i read the very cool guide you made, i discovered a lot ! thanks again. :)

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

You can set friction really high if you want. Drag an oildraum in the scene and try to change it s friction. you can go really high.

I agree with that. I think Lua is really good to understand, at least when the documentation is correct or present. And then there is this problem: http://leadwerks.com/werkspace/index.php?/topic/1582-proper-lua-syntax-highlighting/

 

I assume you have taken a look a the vehicle examples that come with the sdk?

 

Glad that the LUG helped you out! :)

Link to comment
Share on other sites

i am a bit disappointed with lua things,

 

in my pro real life, i'm coding a bit with vbs script, the objects exposed by windows are such easy to grab, name and manipulate that it is a game for me.

 

BUT here in lua all that i can grab from my loaded model is a memory pointer in hexa form that is useless for me,

to be short, i need to retrieve names, position rotation of these "children" of my parent model and "CHANGE" it, but i don't know how, i tried with

 

for k,v in pairs(object) do ...

 

but no luck, is it a security thing that we can't explore a "GMF" model with ease ? (like in model viewer ?)

need to dig in lua "metatables" and "__index", "self" things....

 

sorry to appear :)

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

thx for the link, i saw it before but don't remember where, Rick is always an helper.

 

other things, i found the "turret" code thing in viperscout.lua which is handy for what i need, and yes it is by "FindChild" way

 

EDIT:

i put a video on my blog with my running car

Edited by diedir

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

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

 Share

×
×
  • Create New...