NovaCrew Posted January 29, 2023 Share Posted January 29, 2023 Hello, I want to make a amphibious vehicle like for example AAV7. Is it possible to make a vehicle "swim" in mta? And if yes, then how to make it? Link to comment
Trust aka Tiffergan Posted January 29, 2023 Share Posted January 29, 2023 local speed = 20 local buoyancy = 1.5 local drag = 1 function swimVehicle ( ) local x, y, z = getElementPosition(vehicle) local waterZ = getWaterLevel ( x, y, z ) if waterZ and z < waterZ then setElementData(vehicle, "buoyancy", buoyancy) setElementData(vehicle, "vehicleDrag", drag) setElementData(vehicle, "centerOfMass", {0,0,-1}) setVehicleHandling(vehicle, "engineAcceleration", speed) else setElementData(vehicle, "buoyancy", 0) setElementData(vehicle, "vehicleDrag", 0) setVehicleHandling(vehicle, "engineAcceleration", 0) end end addEventHandler("onClientRender", root, swimVehicle) Please note that this is just a basic example, you would need to fine tune the values and add more functionality to make it more realistic and functional. Also, this example is for client-side script, you need to adapt it for server-side. Link to comment
NovaCrew Posted January 30, 2023 Author Share Posted January 30, 2023 (edited) 16 hours ago, Trust aka Tiffergan said: local speed = 20 local buoyancy = 1.5 local drag = 1 function swimVehicle ( ) local x, y, z = getElementPosition(vehicle) local waterZ = getWaterLevel ( x, y, z ) if waterZ and z < waterZ then setElementData(vehicle, "buoyancy", buoyancy) setElementData(vehicle, "vehicleDrag", drag) setElementData(vehicle, "centerOfMass", {0,0,-1}) setVehicleHandling(vehicle, "engineAcceleration", speed) else setElementData(vehicle, "buoyancy", 0) setElementData(vehicle, "vehicleDrag", 0) setVehicleHandling(vehicle, "engineAcceleration", 0) end end addEventHandler("onClientRender", root, swimVehicle) Please note that this is just a basic example, you would need to fine tune the values and add more functionality to make it more realistic and functional. Also, this example is for client-side script, you need to adapt it for server-side. well, I really don't know what to type there xd (it's that server-side script) Edited January 30, 2023 by NovaCrew 1 Link to comment
FLUSHBICEPS Posted February 8, 2023 Share Posted February 8, 2023 addEventHandler("onVehicleEnter", root, function(player, seat) if source:getModel() == 416 then setElementData(source, "canDriveOnWater", true) end end) addEventHandler("onVehicleExit", root, function(player, seat) if source:getModel() == 416 and getElementData(source, "canDriveOnWater") then setElementData(source, "canDriveOnWater", false) setVehicleHandling(source, "dragCoeff", 0.2) end end) addEventHandler("onClientPreRender", root, function() for i, vehicle in ipairs(getElementsByType("vehicle")) do if getElementData(vehicle, "canDriveOnWater") then local x, y, z = getElementPosition(vehicle) if getWaterLevel(x, y, z) > z then setVehicleOnGround(vehicle) setVehicleHandling(vehicle, "dragCoeff", 10) else setVehicleHandling(vehicle, "dragCoeff", 0.2) end end end end) not tested tho Link to comment
FLUSHBICEPS Posted February 8, 2023 Share Posted February 8, 2023 addEventHandler("onVehicleEnter", root, function(player, seat) if source:getModel() == 416 then setElementData(source, "canDriveOnWater", true) end end) addEventHandler("onVehicleExit", root, function(player, seat) if source:getModel() == 416 and getElementData(source, "canDriveOnWater") then setElementData(source, "canDriveOnWater", false) setVehicleHandling(source, "dragCoeff", 0.2) end end) addEventHandler("onVehicleMove", root, function() local vehicle = source if getElementData(vehicle, "canDriveOnWater") then local x, y, z = getElementPosition(vehicle) if getWaterLevel(x, y, z) > z then setVehicleOnGround(vehicle) setVehicleHandling(vehicle, "dragCoeff", 10) else setVehicleHandling(vehicle, "dragCoeff", 0.2) end end end) My apologies I did a mistake with the event, I’ve replaced it with my onVehicleMove now it should work literally sometimes I forget it’s for MTA addEventHandler("onVehicleEnter", root, function(player, seat) if getElementModel(source) == 416 then setElementData(source, "canDriveOnWater", true) end end) addEventHandler("onVehicleExit", root, function(player, seat) if getElementModel(source) == 416 and getElementData(source, "canDriveOnWater") then setElementData(source, "canDriveOnWater", false) if getVehicleHandling(source)["dragCoeff"] then setVehicleHandling(source, "dragCoeff", 0.2) end end end) addEventHandler("onVehicleMove", root, function() local vehicle = source if getElementData(vehicle, "canDriveOnWater") then local x, y, z = getElementPosition(vehicle) local waterZ = getWaterLevel(x, y, z) if waterZ and waterZ > z then setElementPosition(vehicle, x, y, waterZ) if getVehicleHandling(vehicle)["dragCoeff"] then setVehicleHandling(vehicle, "dragCoeff", 10) end else if getVehicleHandling(vehicle)["dragCoeff"] then setVehicleHandling(vehicle, "dragCoeff", 0.2) end end end end) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now