Jump to content

vehicle_monstertruck.lua_tireOrder


flachdrache
 Share

Recommended Posts

I noticed that the tires of the leadwerks_monstertruck are called in a wrong order - assuming its left-left, right-right :

 

vehicle_monstertruck.lua

 

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
					speed = Clamp( speed, 0, 1 ) * 0.5
					if speed>0 then
						self.emitter[n]:Resume()
						self.emitter[n]:SetColorf(1,1,1,speed)
					end
				end
			end
		end
	end
end

local pivot
local suspensionlength=0.1
local springconstant=25.0
local springdamper=115.0

object.vehicle=CreateVehicle(object.model)
object.tire={}
object.emitter={}

pivot=object.model:FindChild("tireL1")
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::vehicle_monstertruck_tire_left.gmf",object.model)
	pivot:Hide()
end

pivot=object.model:FindChild("tireR1")
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::vehicle_monstertruck_tire_left.gmf",object.model)
	pivot:Hide()
end	

pivot=object.model:FindChild("tireL2")
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::vehicle_monstertruck_tire_right.gmf",object.model)
	pivot:Hide()
end


pivot=object.model:FindChild("tireR2")
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::vehicle_monstertruck_tire_right.gmf",object.model)
	pivot:Hide()
end	

object.emitter={}
object:UpdateTires()

if world_transparency~=nil then
	if world_main~=nil then
		SetWorld(world_transparency)
		for n=0,3 do
			if object.tire[n]~=nil then
				object.emitter[n]=CreateEmitter(50,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(1,6)
				object.emitter[n]:SetWaver(1.0)
				object.emitter[n]:Paint(LoadMaterial("abstract::roaddust.mat"))
				object.emitter[n]:SetRotationSpeed(0.1)
				object.emitter[n]:Pause()
			end
		end
		SetWorld(world_main)
	end
end

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

 

which makes the driver_Truck.lua :

 

require("Scripts/constants/keycodes")
require("Scripts/constants/collision_const")
require("Scripts/linkedlist")
require("Scripts/filesystem")
require("scripts/math/math")
require("scripts/constants/engine_const")

FlushKeys()
HideMouse()

local camera = fw.main.camera

chassis=LoadModel("abstract::vehicle_monstertruck.gmf")
carobject=objecttable[chassis]
truck=carobject.vehicle

if truck==nil then
Notify("Vehicle object not found.",1)
chassis:Free()
return
end

chassis:SetPosition(TFormPoint(Vec3(0,-1,15),fw.main.camera,nil))
chassis:SetRotationf(0,camera.rotation.y+180.0,0)

--Variables
local dx=0.0
local dy=0.0
local camerapitch=camera.rotation.x
local camerayaw=camera.rotation.y
local move=0.0
local strafe=0.0
local steering = 0.0
local torque = 0.0
local steerlimit = 30.0
local steerrate = 2.0
local steerangle=0.0

MoveMouse(Round(GraphicsWidth()/2),Round(GraphicsHeight()/2))

while KeyHit(KEY_ESCAPE)==0 do	

--Camera look
gx=Round(GraphicsWidth()/2)
gy=Round(GraphicsHeight()/2)
dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())
dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())
MoveMouse(gx,gy)
camerapitch=camerapitch+dy
camerayaw=camerayaw-dx
camerapitch=math.min(camerapitch,60)
camerapitch=math.max(camerapitch,-10)

fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)

local tirespeed=-(KeyDown(KEY_W)-KeyDown(KEY_S))*2.0
truck:AddTireTorque(tirespeed,0)
truck:AddTireTorque(tirespeed,1)

truck:AddTireTorque(tirespeed,2)
truck:AddTireTorque(tirespeed,3)

steermode=0
if KeyDown(KEY_D)==1 then steermode=steermode-1 end
if KeyDown(KEY_A)==1 then steermode=steermode+1 end

if KeyDown(KEY_SPACE)==1 then 
	chassis:SetPosition(chassis:GetPosition())
	chassis:SetVelocity(Vec3(0))
end

if steermode==1 then
	steerangle=steerangle+4.0*AppSpeed()
elseif steermode==-1 then
	steerangle=steerangle-4.0*AppSpeed()
else
	if steerangle>0 then
		steerangle=steerangle-4.0*AppSpeed()
		if steerangle<0.0 then steerangle=0.0 end
	else
		steerangle=steerangle+4.0*AppSpeed()
		if steerangle>0.0 then steerangle=0.0 end
	end
end
steerangle=Clamp(steerangle,-23,23)

truck:SetSteerAngle(steerangle,0)
truck:SetSteerAngle(steerangle,1)

fw:Update()

local campos=TFormPoint(Vec3(0,1,0),chassis,nil)

fw.main.camera:SetPosition(campos)
fw.main.camera:Move(Vec3(0,0,-10))

local t=TFormVector(Vec3(0,0,1),camera,chassis)
a=-math.deg(math.atan2(t.x,t.z))+180.0

chassis:Hide()
local pick = LinePick(campos,camera.position,0.5,COLLISION_PROP)
chassis:Show()
if pick~=nil then
	camera:SetPosition(pick.position)
end

fw:Render()
Flip(0)
end

chassis:Free()
chassis=nil
camera=nil

ShowMouse()

 

PS: changed KEY_UP etc. to KEY_W etc. in this script.

AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3

zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5

 

adv_banner-april2012_720x150_tex01.png

 

Xxploration FPS in progress ...

Link to comment
Share on other sites

Yep, thanks for the share TLD I am sure that is going to come in handy :unsure:

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Since there is no LoadScript in c++ anymore, How could i get this to run in my c++ project?

 

I'm using LEO with support for Lua, from example Lummoja posted. Just plain project with character controller.

 

If i drag the monstertruck into my map, i see it's in there rolling around, but how do i load the "driver_truck.lua" script?

 

 

 

Thank's for any tips..

Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI.

Link to comment
Share on other sites

Thank's for the link VicToMeyeZR, i have my project setup like that.

 

I think i was confusing the "driver_truck.lua" script with the "vehicle_monstertruck.lua" script.

Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI.

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