Background:
Basically, the vehicle needs to collide with all the usual things over land (ie. collision_mask=player_layer), but not be prevented from skimming over water.
Simply removing the mask from water tiles is no good because the bare character shouldn't be able to walk over it, and turning up the friction causes the player to get stuck in water (doesn't behave like a wall as it does with a collision mask). To my understanding, you can't alter the entity collision mask in runtime.
So, to resolve this there are two vehicles, one for land with collision mask, one for water without. control.lua swaps the vehicles as you drive into/away from water.
Issue:
There is a perceptible twitch as this swap happens.
I believe it's because the game is placing the character next to the first vehicle for a split second when it's destroyed, before inserting into the second.
Any thoughts on how to resolve this?
Rough vehicle swapping code here:
Code: Select all
local function swapVehicle(oldCar,newCarType)
local newCar = oldCar.surface.create_entity{name=newCarType,position=oldCar.position,force=oldCar.force}
newCar.orientation = oldCar.orientation
newCar.speed = oldCar.speed
newCar.health = oldCar.health
newCar.burner.currently_burning = oldCar.burner.currently_burning
newCar.burner.remaining_burning_fuel = oldCar.burner.remaining_burning_fuel
local driver = oldCar.get_driver()
local passenger = oldCar.get_passenger()
for k,v in pairs({carFuel,carTrunk}) do
for n,c in pairs(oldCar.get_inventory(v).get_contents()) do
newCar.get_inventory(v).insert({name = n, count = c})
end
end
oldCar.destroy()
newCar.set_driver(driver)
newCar.set_passenger(passenger)
end