There is always something new to learn, and when my native language is not English, there is a way of learning called brute force, this leads to two things, first, you learn, and second a high percentage is learning to do things wrong, of course not always.
Today I had a kind of Eureka, I actually discovered how to properly implement the sliding joints to create springs for a vehicle, the point here is to get to understand how this should work and I think I've achieved it. In the end I'm left with the doubt of whether I have a learning disability, because torture is the same as always, trial and error.
Translated with www.DeepL.com/Translator
So I expose the code to recreate the shock absorbers, it should be noted that only I understand this, because I do not give any explanation regarding the case, but it works.
cVehicle={}
function cVehicle:New()
local this = {}
this.mesh = {}
this.mesh.chassis = nil
--## pivots Springs.
this.mesh.SpringFL = nil
this.mesh.SpringFR = nil
this.mesh.SpringBL = nil
this.mesh.SpringBR = nil
--## Meshs Wheels.
this.mesh.WheelFL = nil
this.mesh.WheelFR = nil
this.mesh.WheelBL = nil
this.mesh.WheelBR = nil
--## Meshs Axles Dir.
this.mesh.AxleL = nil
this.mesh.AxleR = nil
--## Motor Springs.
this.motorSprings={}
this.motorSprings.force = 300
this.motorSprings.limits={}
this.motorSprings.limits.Down = -0.5
this.motorSprings.limits.Up = 0.5
this.posSprings={}
function this:StartSystem( springs, wheels, axles, chassis)
self.mesh.chassis = chassis
self.mesh.SpringFL = springs[0]
self.mesh.SpringFR = springs[1]
self.mesh.SpringBL = springs[2]
self.mesh.SpringBR = springs[3]
self.mesh.WheelFL = wheels[0]
self.mesh.WheelFR = wheels[1]
self.mesh.WheelBL = wheels[2]
self.mesh.WheelBR = wheels[3]
self.mesh.AxleL = axles[0]
self.mesh.AxleR = axles[1]
self:StartMotorSprings()
end
function this:StartMotorSprings()
self.posSprings[0] = self.mesh.SpringFL:GetPosition(true)
self.motorSprings[0] = Joint:Slider( self.posSprings[0].x,self.posSprings[0].y,self.posSprings[0].z, 0,1,0,self.mesh.SpringFL, self.mesh.chassis )
self.motorSprings[0]:EnableLimits()
self.motorSprings[0]:SetLimits( self.motorSprings.limits.Down, self.motorSprings.limits.Up)
self.motorSprings[0]:SetSpring( this.motorSprings.force )
self.posSprings[1] = self.mesh.SpringFR:GetPosition(true)
self.motorSprings[1] = Joint:Slider( self.posSprings[1].x,self.posSprings[1].y,self.posSprings[1].z, 0,1,0,self.mesh.SpringFR, self.mesh.chassis )
self.motorSprings[1]:EnableLimits()
self.motorSprings[1]:SetLimits( self.motorSprings.limits.Down, self.motorSprings.limits.Up )
self.motorSprings[1]:SetSpring( this.motorSprings.force )
self.posSprings[2] = self.mesh.SpringBL:GetPosition(true)
self.motorSprings[2] = Joint:Slider( self.posSprings[2].x,self.posSprings[2].y,self.posSprings[2].z, 0,1,0,self.mesh.SpringBL, self.mesh.chassis )
self.motorSprings[2]:EnableLimits()
self.motorSprings[2]:SetLimits( self.motorSprings.limits.Down, self.motorSprings.limits.Up )
self.motorSprings[2]:SetSpring( this.motorSprings.force )
self.posSprings[3] = self.mesh.SpringBR:GetPosition(true)
self.motorSprings[3] = Joint:Slider( self.posSprings[3].x,self.posSprings[3].y,self.posSprings[3].z, 0,1,0,self.mesh.SpringBR, self.mesh.chassis )
self.motorSprings[3]:EnableLimits()
self.motorSprings[3]:SetLimits( self.motorSprings.limits.Down, self.motorSprings.limits.Up )
self.motorSprings[3]:SetSpring( this.motorSprings.force )
end
function this:Update()
if Window:GetCurrent():KeyDown(Key.J) then
self.mesh.chassis:AddForce(0,150,0)
end
end
return this
end
And there's still the question of whether this is well implemented, but I guess I've learned something new.