Here Script vehicle System.
-- **********************************************************
-- Fichero Script : CVehicle.lua
-- Notas : Fichero Clase para objeto / Vehiculo.
-- Scripter : Yue Rexie.
-- **********************************************************
-- Sitio Web : http://www.iris3dgames.ga
-- Fecha : Viernes 10 de Enero / 2020
-- **********************************************************
vehicle = {}
function vehicle:New(chassis,wheels,springs,axis)
local this = {}
function this:Start()
this.chassis = chassis
this.wheels = wheels
this.springs = springs
this.axis = axis
this.axisFL = nil
this.axisFR = nil
this.springFL = nil
this.springFR = nil
this.springBL = nil
this.springBR = nil
this.hingeWFL = nil
this.hingeWFR = nil
this.hingeWBL = nil
this.hingeWBR = nil
end
this:Start()
function this:Init()
self:InitSprings()
self:InitMotorWheels()
self:InitAxisW()
end
function this:InitAxisW()
self.axisFL = self:CreateHinge(self.axis.FL, self.springs.FL,0,1,0)
self.axisFR = self:CreateHinge(self.axis.FR, self.springs.FR,0,1,0)
self.axisFL:EnableLimits()
self.axisFR:EnableLimits()
self.axisFL:SetLimits(0,0)
self.axisFR:SetLimits(0,0)
end
function this:InitSprings()
self.springFL = self:CreateSpring(self.springs.FL)
self.springFR = self:CreateSpring(self.springs.FR)
self.springBL = self:CreateSpring(self.springs.BL)
self.springBR = self:CreateSpring(self.springs.BR)
end
function this:InitMotorWheels()
self.hingeWFL = self:CreateHinge(self.wheels.FL,self.axis.FL, 1,0,0)
self.hingeWFR = self:CreateHinge(self.wheels.FR,self.axis.FR, 1,0,0)
self.hingeWBL = self:CreateHinge(self.wheels.BL,self.springs.BL,1,0,0)
self.hingeWBR = self:CreateHinge(self.wheels.BR,self.springs.BR,1,0,0)
end
function this:Update()
if Window:GetCurrent():KeyDown(Key.F) then
self.chassis:AddForce(0,5000,0)
end
end
-- Joints.
function this:CreateHinge(child,parent,pinX, pinY, pinZ)
local posChild = child:GetPosition(false)
local h = Joint:Hinge(posChild.x, posChild.y, posChild.z, pinX, pinY, pinZ, child, parent)
return h
end
function this:CreateSpring(spring)
local posSpring = spring:GetPosition(false)
local s = Joint:Slider(posSpring.x,posSpring.y,posSpring.z, 0,1,0,spring, self.chassis )
s:EnableLimits()
s:SetLimits(-0.05,0.02)
s:SetSpring(1,0.5,1)
return s
end
return this