Community Forum

Modifying vehicle properties

Forum Overview >> Scripting

CategoryScripting
Created17.02.2022 00:48


Bram Nic (bn122) 17.02.2022 00:48
A simple question, what's the best way to modify eg. the mass of a vehicle or the dampener settings for wheels.
Not sure where to find the right properties and how to override them.

Vehicle.mass is probably not what I'm looking for but not sure how to access or find the right one. I can't find it through the luadoc/sdk either.

ModVehicleProperties = {};

function ModVehicleProperties.prerequisitesPresent(specializations)
return true
end;

function ModVehicleProperties:onUpdate(dt)
if self.ModVehicleProperties == nil then
self.ModVehicleProperties = "applied";
if self.spec_motorized ~= nil then
if self.spec_motorized.motor ~= nil then
Vehicle.mass = Vehicle.mass * 50;
end;
end;
end;
end;
Drivable.onUpdate = Utils.prependedFunction(Drivable.onUpdate, ModVehicleProperties.onUpdate);

And a more advanced question: how are things like wheel bumps/sink generally implemented and how can the behaviour be modified to be active all the time? Wheels.OnUpdate and Wheels:updateWheelSink(wheel, dt, groundWetness) seem to be doing these things but not sure how to override/add functionality to this in a mod.

M********* R******** (sharecropper27) 19.02.2022 14:05
Mass is modified in the XML under <base> here:

<base>
<typeDesc>$l10n_typeDesc_combine</typeDesc>
<filename>gleaner.i3d</filename>
<sounds filename="$data/sounds/vehicle.xml" />
<size width="5" length="11" lengthOffset="0"/>
<components>
<component centerOfMass="0 0.5 0" solverIterationCount="200" mass="10000"/>
<component centerOfMass="0 0 0" solverIterationCount="200" mass="9000"/>
<joint component1="1" component2="2" node="0>16" rotLimit="0 0 5" transLimit="0 0 0"/>
</components>
<schemaOverlay attacherJointPosition="0.5 0" name="HARVESTER"/>
<mapHotspot type="THIS IS WHAT SHOWS UP ON THE MAP" />

</base>


Damper can be modified in the XML under <wheels> here:
<wheels>
<wheelConfigurations>
<!-- Narrow -->
<wheelConfiguration name="$l10n_configuration_valueDefault" price="0" brand="MICHELIN">
<wheels autoRotateBackSpeed="1.8">
<wheel filename="$data/shared/wheels/tires/michelin/megaXbib/620_70R42.xml" isLeft="true" hasTireTracks="true" hasParticles="true">
<physics tipOcclusionAreaGroupId="1" restLoad="2.0" repr="leftFrontMichelin" forcePointRatio="0.5" frictionScale="6" initialCompression="10" suspTravel="0.22" spring="59" damper="40" />
</wheel>
<wheel filename="$data/shared/wheels/tires/michelin/megaXbib/620_70R42.xml" isLeft="false" hasTireTracks="true" hasParticles="true">
<physics tipOcclusionAreaGroupId="1" restLoad="2.0" repr="rightFrontMichelin" forcePointRatio="0.5" frictionScale="6" initialCompression="10" suspTravel="0.22" spring="59" damper="40" />
</wheel>


My understanding of wheel sink is "initial compression" modifies how the vehicle sits in relation to load. i.e. @10% full the wheels aren't affected but 100% full can cause a wheel to clip into the trailer fenders/frame et cetera. hope that helps and if not, i'd like to know as well.

Bram Nic (bn122) 19.02.2022 22:37
Thanks for your response. Do you know what the syntax would be to modify the mass in the <base> section? I know how to edit XML's but want to know how to modify it in LUA, that's what I'm still unfamiliar with.

Modifying the compression value could be a interesting approach to simulate road bumps on terrain. I was otherwise considering overriding the Wheel.Update functions but that may be a lot more complex in order to keep physics working well.



Bram Nic (bn122) 21.02.2022 00:31
Ok found the syntax to set mass. Unfortunately it doesn't seem to have any effect on vehicles. The value is definitely set.
Tried both appendedFunction and prependedFunction but neither make a difference, any ideas?

if self.components ~= nil then
if self.components[0] ~= nil then
self.components[0].mass = self.components[0].mass * massMultiplier;
end
if self.components[1] ~= nil then
self.components[1].mass = self.components[1].mass * massMultiplier;
end
end;
Drivable.onUpdate = Utils.appendedFunction(Drivable.onUpdate, ModVehicleProperties.onUpdate);

M********* R******** (sharecropper27) 24.02.2022 15:32
I have a stupid question but worth a shot: what happens if you change the vector three (x,y,z) in this scenario? Is this even a factor? I'm attempting to understand how this particular function affects the model in 3D space. I'm more of a visual person but searching for an answer. I'd like to know this as well

Is the mass read-write or read-only?

Bram Nic (bn122) 24.02.2022 18:06
When I re-read the value of mass it is set to whatever I set it to previously so it should be writable, however the vehicle doesn't seem to change in behaviour. Must be some kind of run order of the functions. I would assume Drivable.onUpdate executes pretty late

That vector is used in Vehicle.lua; must be a engine/physics property for components
local comX, comY, comZ = xmlFile:getValue(key .. "#centerOfMass")
if comX ~= nil then
setCenterOfMass(component.node, comX, comY, comZ)
end

M********* R******** (sharecropper27) 24.02.2022 21:03
You might try using "while" and "do" to account for Drivable.onUpdate

if self.components ~= nil then
if self.components[0] ~= nil then
self.components[0].mass = self.components[0].mass * massMultiplier;
end
if self.components[1] ~= nil then
self.components[1].mass = self.components[1].mass * massMultiplier;
end
end;
Drivable.onUpdate = Utils.appendedFunction(Drivable.onUpdate, ModVehicleProperties.onUpdate);



function
if self.components ~= nil then
if self.components[0] ~= nil then
if self.components[1] ~= nil then
self.components[1].mass = self.components[1].mass * massMultiplier;
end
while (self.components[1].mass * massMultiplier) > self.components[0].mass) do
--
-- Insert your code here<!--unsure about what goes here-->
--
end
end;
Drivable.onUpdate = Utils.appendedFunction(Drivable.onUpdate, ModVehicleProperties.onUpdate);





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