Community Forum

Clone wheels problem

Forum Overview >> Scripting

CategoryScripting
Created27.09.2011 16:55


Milan Lekše (Unknown) 27.09.2011 17:05
HI

I created a little script to do double wheels for all vehicles, but my clone wheels looks like they have no ground contact -- they go below the ground everything else I have done weary well have rotation position near original wheel …
Here is the code - it is copied from vehicle.lua::

if self.isClient then
self.kolesa = {};
local i = 0;
while true do
local wheelnamei = string.format("vehicle.wheels.wheel(%d)", i);
local wheel = {};
local reprStr = getXMLString(xmlFile, wheelnamei .. "#repr");
if reprStr == nil then
break;
end;
wheel.repr = Utils.indexToObject(self.components, reprStr);

if wheel.repr == nil then
print("Error: invalid wheel repr " .. reprStr);
else
wheel.offset = 0.8
wheel.rotSpeed = Utils.degToRad(getXMLFloat(xmlFile, wheelnamei .. "#rotSpeed"));
wheel.rotMax = Utils.degToRad(getXMLFloat(xmlFile, wheelnamei .. "#rotMax"));
wheel.rotMin = Utils.degToRad(getXMLFloat(xmlFile, wheelnamei .. "#rotMin"));
wheel.driveMode = Utils.getNoNil(getXMLInt(xmlFile, wheelnamei .. "#driveMode"), 0);
wheel.driveNodeA = Utils.indexToObject(self.components, getXMLString(xmlFile, wheelnamei .. "#driveNode"));
wheel.driveNode = clone(self.wheels[i+1].driveNode);
setScale(wheel.driveNode,1,1,1)
if wheel.driveNodeA == nil then
wheel.offset = 0.0001
wheel.driveNodeA = wheel.repr;
end;
wheel.showSteeringAngle = Utils.getNoNil(getXMLBool(xmlFile, wheelnamei .. "#showSteeringAngle"), true);
local radius = Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#radius"), 1);
local positionX, positionY, positionZ = getTranslation(wheel.driveNodeA);
local posX, posY, posZ = getTranslation(wheel.repr);
wheel.deltaY = Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#deltaY"), 0.0);
positionY = positionY+wheel.deltaY;
local suspTravel = Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#suspTravel"), 0);
local spring = Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#spring"), 0)*Vehicle.springScale;
local damper = Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#damper"), 0);
wheel.mass = Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#mass"), 0.01);
wheel.radius = radius;
wheel.steeringAxleScale = Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#steeringAxleScale"), 0);
wheel.steeringAxleRotMax = Utils.degToRad(Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#steeringAxleRotMax"), 20));
wheel.steeringAxleRotMin = Utils.degToRad(Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#steeringAxleRotMin"), -20));
wheel.lateralStiffness = Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#lateralStiffness"), 19);
wheel.longitudalStiffness = Utils.getNoNil(getXMLFloat(xmlFile, wheelnamei .. "#longitudalStiffness"), 1);
wheel.steeringAngle = 0;
wheel.hasGroundContact = true;
wheel.axleSpeed = 0;
wheel.hasHandbrake = true;
wheel.visibility = false
wheel.node = wheel.driveNode;
if self.isServer then

wheel.wheelShape = createWheelShape(wheel.driveNode, positionX, 0, 0, radius, 0, 0, 0, 0.01);

setWheelShapeTireFunction(wheel.driveNode, wheel.wheelShape, false, 1000000*19);
setWheelShapeTireFunction(wheel.driveNode, wheel.wheelShape, true, 1000000*1);
end;

wheel.netInfo = {};
wheel.netInfo.xDrive = 0;
wheel.netInfo.x = positionX;
wheel.netInfo.y = 0;
wheel.netInfo.z = 0;

wheel.netInfo.yMin = 0-suspTravel;
wheel.netInfo.yRange = math.ceil(2*suspTravel);
if wheel.netInfo.yRange < 1 then
wheel.netInfo.yRange = 1;
end;
if posX < 0 then
wheel.offset = wheel.offset * -1
end

setTranslation(wheel.driveNode, positionX+wheel.offset, 0, 0)
link(wheel.driveNodeA, wheel.driveNode);

setVisibility(wheel.driveNode, wheel.visibility);

table.insert(self.kolesa, wheel);
end;
i = i+1;
end;
end
thnx for great game, opencode and helping me


Ludovic Fritz (mrludo40) 02.10.2011 03:46
hello, I'm not sure it'll be able to help you but I have a script for the wheel

Wheel. lua

wheehl = {};

function wheehl.prerequisitesPresent(specializations)
Vehicle.registerJointType("Quicke");
return true;
end;

function wheehl:load(xmlFile)
local NumVisWheelsParts = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.WheelsVis#count"), 0);
self.VisWheels = {};
for i=1, NumVisWheelsParts do
local partnamei = string.format("vehicle.WheelsVis.Wheel" .. "%d", i);
self.VisWheels[i] = {};
self.VisWheels[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei .. "#index"));
self.VisWheels[i].index2 = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei .. "#index2"));
self.VisWheels[i].Change = Utils.getNoNil(getXMLString(xmlFile, partnamei .. "#Change"),"false");
setVisibility(self.VisWheels[i].index, true);
setVisibility(self.VisWheels[i].index2, false);
end;
self.WheelsVis = false

end;

function wheehl:delete()
end;

function wheehl:mouseEvent(posX, posY, isDown, isUp, button)
end;

function wheehl:keyEvent(unicode, sym, modifier, isDown)
end;

function wheehl:update(dt)

if self:getIsActiveForInput() then
if InputBinding.hasEvent(InputBinding.SwitchWheel) then
self.WheelsVis = not self.WheelsVis;
end;
end;

for i=1, table.getn(self.VisWheels) do
setVisibility(self.VisWheels[i].index2, self.WheelsVis);
if self.VisWheels[i].Change == "true" then
setVisibility(self.VisWheels[i].index, not self.WheelsVis);
else
setVisibility(self.VisWheels[i].index, true);
end;
end;


end;
function wheehl:draw()
if self.isEntered then
g_currentMission:addHelpButtonText(g_i18n:getText("SwitchWheel"), InputBinding.SwitchWheel);
end;
end;


in your file you put modDesc.xml

<specializations>
<specialization name="wheels" className="wheehl" filename="Scripts/wheel.lua"/>
</specializations>

<vehicleTypes>
<type name="name of the mod" className="Vehicle" filename="$dataS/scripts/vehicles/Vehicle.lua">
<specialization name="wheels" />
</type>
</vehicleTypes>



and in the file mod.xml

If you add this

<numWheels>4</numWheels>
<wheels autoRotateBackSpeed="2.5">
<wheel rotSpeed="45" rotMax="25" rotMin="-25" driveMode="2" repr="0" driveNode="0|0" radius="1" deltaY="0.1" suspTravel="0.2" spring="280" damper="2" mass="0.35" lateralStiffness="40" />
<wheel rotSpeed="45" rotMax="25" rotMin="-25" driveMode="2" repr="1" driveNode="1|0" radius="1" deltaY="0.1" suspTravel="0.2" spring="280" damper="2" mass="0.35" lateralStiffness="40" />
<wheel rotSpeed="-45" rotMax="15" rotMin="-15" driveMode="2" repr="2" driveNode="2|0" radius="1" deltaY="0.1" suspTravel="0.2" spring="280" damper="2" mass="0.35" lateralStiffness="40" />
<wheel rotSpeed="-45" rotMax="15" rotMin="-15" driveMode="2" repr="3" driveNode="3|0" radius="1" deltaY="0.1" suspTravel="0.2" spring="280" damper="2" mass="0.35" lateralStiffness="40" />
<wheel rotSpeed="-45" rotMax="15" rotMin="-15" driveMode="2" repr="23" driveNode="23|0" radius="1" deltaY="0.1" suspTravel="0.2" spring="280" damper="2" mass="0.35" lateralStiffness="40" />
<wheel rotSpeed="-45" rotMax="15" rotMin="-15" driveMode="2" repr="24" driveNode="24|0" radius="1" deltaY="0.1" suspTravel="0.2" spring="280" damper="2" mass="0.35" lateralStiffness="40" />
<wheel rotSpeed="45" rotMax="25" rotMin="-25" driveMode="2" repr="12" driveNode="12|0" radius="1" deltaY="0.1" suspTravel="0.2" spring="280" damper="2" mass="0.35" lateralStiffness="40" />
<wheel rotSpeed="45" rotMax="25" rotMin="-25" driveMode="2" repr="13" driveNode="13|0" radius="1" deltaY="0.1" suspTravel="0.2" spring="280" damper="2" mass="0.35" lateralStiffness="40" />
</wheels>

<WheelsVis count="4">
<Wheel1 index="1" index2="12" Change="false"/>
<Wheel2 index="2" index2="13 " Change="false"/>
<Wheel3 index="3" index2="23" Change="false"/>
<Wheel4 index="4" index2="24" Change="false"/>
</WheelsVis>



Here I hope I have helped you

Milan Lekše (Unknown) 03.10.2011 14:21
Ludovic Fritz thnx for helping, but I alrady change my script it's now working it will be uplouded to http://www.ls-uk.info/ and some other things in one pack, but I have now new problem how to delete wheelShape

Unknown 03.10.2011 14:29
Ludovic Fritz thnx for helping, but I alrady change my script it's now working it will be uplouded to http://www.ls-uk.info/ and some other things in one pack, but I have now new problem how to delete wheelShape

Ludovic Fritz (mrludo40) 06.10.2011 17:42
I use this script on my mods that we have 8 wheel or I create them
So for shapeWheel I do not know you because you want to create aditional 4 wheel of a tractor are only four such right??

Milan Lekše (Unknown) 10.10.2011 10:14
Ludovic Fritz; yes i'ts right, I have fully functional script now, creates on original 4 wheels 4 new, then I in game set wright position - near original wheels, beacouse script is made for all vheicles and some have nerrow others wide wheels, sow for every one wheel I have setings +-, and then on end setings, create shape yes no, if you have no wheels are only images with no function of course they rotate and stearing but if tractors turn on side they go below ground, in the other side if you have yes they are fully functional like original wheels, only I have steel two problems how to get the same rotation like original, having some script, but it's 95% accuracy on high speed and 50% accuracy on low speed, so speeds are sometimes a littel bit difrent like in original, and secondproblem how to remove wheel shape, there is no function to do this - once you create for wheels you can't remove it in game - this I have fixed like this you in game remove aditional wheels, save game and exit on new load aditional wheels are not loaded.

of course all changes made for wheels are saved so you dont have to add new wheels every time you start the game

next step is add this to implements too

thnx for helping


Note: Log in to post. Create a new account here.