Jump to content

How to create a Slider Joint?


Alessandro
 Share

Recommended Posts

Hello,

I need to create slider joint to make a suspension, but I get always an errore from LE.

This is the code:

 

	local myWheelFL = LoadModel("abstract::" .. "vehicle_proto_wheel.gmf", object.model)
local myWheelFR = LoadModel("abstract::" .. "vehicle_proto_wheel.gmf", object.model)
local myWheelRL = LoadModel("abstract::" .. "vehicle_proto_wheel.gmf", object.model)
local myWheelRR = LoadModel("abstract::" .. "vehicle_proto_wheel.gmf", object.model)

if myWheelFL == nil then
	Notify("Errore creazione wheel")
	return
end

myWheelFL:SetPosition(Vec3(-1.6, -0.8, -2))
myWheelFR:SetPosition(Vec3(-1.6, -0.8, 2))
myWheelRL:SetPosition(Vec3(1.6, -0.8, -2))
myWheelRR:SetPosition(Vec3(1.6, -0.8, 2))

-- ******* THIS FUNCTION CALL GIVE ME THE ERROR ***********
object.model:CreateJointSlider(myWheelFL, Vec3(-1.6, -0.8, 2), Vec3(-1.6, 0, 0))

 

 

I get "Index for object is not a valid field or method".

If instead I use

object.model:CreateJointSlider(myWheelFL, Vec3(-1.6, -0.8, 2), Vec3(-1.6, 0, 0))

 

I get:

Attempt to call method (a nil value).

 

But I'm sure the object pointers and the wheels are created (I check them).

 

Please help me!

Link to comment
Share on other sites

Its because CreateJointSlider is not a method of object.model. It should be something like this (assuming the rest of your parameters are filled out correctly):

 

object.joint = CreateJointSlider(myWheelFL, Vec3(-1.6, -0.8, 2), Vec3(-1.6, 0, 0))

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

What should this line be doing?

"abstract::" .. "vehicle_proto_wheel.gmf"

 

Shouldn't it just be:

"abstract::vehicle_proto_wheel.gmf"

 

as far as LoadModel() is concerned it doesn't make a difference since lua just adds the two strings together...

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

What should this line be doing?

"abstract::" .. "vehicle_proto_wheel.gmf"

 

Shouldn't it just be:

"abstract::vehicle_proto_wheel.gmf"

 

Yes, you are right, it was in the first form since the wheel name will be stored in a variable:

 

"abstract::" .. locWheelName

 

:)

 

@macklebee, thank you for your help.

Even if LUA seems a very important piece inside LE, its documentation is not enough, and not clear.

 

I wish a better documentation for the future.

 

Thank you again!

Link to comment
Share on other sites

object.joint = CreateJointSlider(myWheelFL, Vec3(-1.6, -0.8, 2), Vec3(-1.6, 0, 0))

 

The exact syntax (from documentation) is:

 

object.joint = CreateJointSlider(object.model, myWheelFL, Vec3(-1.6, -0.8, 2), Vec3(-1.6, 0, 0))

 

In fact you forgot the parent object :)

 

Cheers! (thank you again!)

Link to comment
Share on other sites

Ok, setting a Newton vehicle in LE is a mess. Too many information are missing!

Pleae Josh give me some hints how to proceed or I will push myself under a real car :)

 

Now I have this code (not work):

 

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

local myWheelFL = LoadModel("abstract::" .. "vehicleProtoWheel.gmf", object.model)
local myWheelFR = LoadModel("abstract::" .. "vehicleProtoWheel.gmf", object.model)
local myWheelRL = LoadModel("abstract::" .. "vehicleProtoWheel.gmf", object.model)
local myWheelRR = LoadModel("abstract::" .. "vehicleProtoWheel.gmf", object.model)

if myWheelFL == nil then
	Notify("Errore creazione myWheelFL")
	return
end
if myWheelFR == nil then
	Notify("Errore creazione myWheelFR")
	return
end
if myWheelRL == nil then
	Notify("Errore creazione myWheelRL")
	return
end
if myWheelRR == nil then
	Notify("Errore creazione myWheelRR")
	return
end

--local locFL = TFormPoint(Vec3(-1.6, -0.8, -2)	, object.model, nil)
local locFL = Vec3(-1.6, -0.8, -2)
myWheelFL:SetPosition(locFL)

--local locFR = TFormPoint(Vec3(-1.6, -0.8, 2)	, object.model, nil)
local locFR = Vec3(-1.6, -0.8, 2)
myWheelFR:SetPosition(locFR)

--local locRL = TFormPoint(Vec3(1.6, -0.8, -2)	, object.model, nil)
local locRL = Vec3(1.6, -0.8, -2)
myWheelRL:SetPosition(locRL)

--local locRR = TFormPoint(Vec3(1.6, -0.8, 2)	, object.model, nil)
local locRR = Vec3(1.6, -0.8, 2)
myWheelRR:SetPosition(locRR)

local myWheelRLJoint = CreateJointSlider(object.model, myWheelRL, locRL, Vec3(locRL.x, locRL.y+0.2, locRL.z))
local myWheelFLJoint = CreateJointSlider(object.model, myWheelFL, locFL, Vec3(locFL.x, locFL.y+0.2, locFL.z))
local myWheelRRJoint = CreateJointSlider(object.model, myWheelRR, locRR, Vec3(locRR.x, locRR.y+0.2, locRR.z))
local myWheelFRJoint = CreateJointSlider(object.model, myWheelFR, locFR, Vec3(locFR.x, locFR.y+0.2, locFR.z))


--[[**********************************************************************************************
**********************************************************************************************]]--
function object:Free()

	--[[-----------------------------------------------------------------------------------------
	-----------------------------------------------------------------------------------------]]--

	if myWheelFLJoint ~= nil then
		FreeJoint(myWheelFLJoint)
		myWheelFLJoint = nil 
	end
	if myWheelFRJoint ~= nil then
		FreeJoint(myWheelFRJoint)
		myWheelFRJoint = nil 
	end
	if myWheelRLJoint ~= nil then
		FreeJoint(myWheelRLJoint)
		myWheelRLJoint = nil 
	end
	if myWheelRRJoint ~= nil then
		FreeJoint(myWheelRRJoint)
		myWheelRRJoint = nil 
	end

	--[[-----------------------------------------------------------------------------------------
	-----------------------------------------------------------------------------------------]]--

	if myWheelFL ~= nil then
		myWheelFL:Free() 
		myWheelFL = nil 
	end
	if myWheelFR ~= nil then
		myWheelFR:Free() 
		myWheelFR = nil 
	end
	if myWheelRL ~= nil then
		myWheelRL:Free() 
		myWheelRL = nil 
	end
	if myWheelRR ~= nil then
		myWheelRR:Free() 
		myWheelRR = nil 
	end

	self.super:Free()--Don't forget this!! end
end

function object:Update()	
	--self.model:Turn(Vec3(GetEntityKey(self.model, "Rotate X"), -1 * tonumber(GetEntityKey(self.model, "Rotate Y", 0)), GetEntityKey(self.model, "Rotate Z")))
end


end

 

 

JOints not work, and I cannot understand how to manage them.

I stored tires as separated models, and I create them as child of the chassis.

Not work.

 

And this is a screenshot:

http://www.mediafire.com/?h87o7eb7z5ukb

 

 

PLEASE!! I need a real vehicle model! PLEASE JOSH! :):(

Link to comment
Share on other sites

Have you tried using the Create vehicle command?

I agree with the documentation on joints. It is not sufficient for most people to make something work with it.

 

Did you have a look at the driver scripts and viper scout script?

 

Of course, I successfully used them. But that is a partially simulated vehicle (it uses raycast and anims to simulate tires and car movement).

I need a realistic car feedback :)

Link to comment
Share on other sites

//The animations are the ones used to simulate wheel movement (up/down) for suspensions.

 

And wheels rotation :)

 

Well, i'm also interested in car with physic wheels, not raycast. Looking like we need to dig into Newtons header and get physic car functions from there.

 

I tried to get some newton programs made in other languages, but it is not easy to convert them in LE style, since Newton implement a simplifed version of the vehicle using special API, and those api are not implementd in LE.

I cannot find clear information how to create a real vehicle even in newton self.

If you can find a source code in any language showing how to create a real vehicle, please send me that, and I will try to convert it in LE (LUA).

Then I will send you the converted code ;)

Link to comment
Share on other sites

 

 

Thank you, I will check them.

I own 3dgs also, and I tried to follow the new vehicle system they use, but is difficult since they use PhysX engine, and API (and their usage) are really different (and I abandonded the conversion).

 

I will check your links (maybe we can extract something good :-)

 

 

EDIT:

A couple of links have the same problem I already found in the past: they refere to a specifi object class existing in Newton engine. This class is specialized to make vehicles.

As per my knowledge, we haven' that class in LE, so we need to create a vehicle from scratch (using basic joints).

 

 

 

Thank you!

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