Hey all, I know that the console allows me to span a vehicle (or a prop) using the function below: core_vehicles.spawnNewVehicle("cardboard_box", {config = 'vehicles/cardboard_box/large.pc'}); I'm trying to span a pile of boxes at random places by using a loop: local items = 0; while (items < 50) do core_vehicles.spawnNewVehicle("cardboard_box", {config = 'vehicles/cardboard_box/large.pc'}); items = items + 1; end However I'd like to have some control where to spawn them, currently they space one after each other equally, which is expected since I'm not specifying where to spawn them. Is it possible to control where to span things (or even the orientation) using this function? I didn't find any references. Thanks in advance.
Hey, here's an example code that spawns those boxes in a circular pattern on Gridmap V2: Code: local items = 10 local offset = vec3(-150, -200, 105) for i = 0, items - 1 do local angle = i / items * 2 * math.pi local x = math.cos(angle) * 10 local y = math.sin(angle) * 10 local z = 0 local vehPos = vec3(x, y, z) + offset local vehRot = quatFromAxisAngle(vec3(0,0,1), -angle) core_vehicles.spawnNewVehicle("cardboard_box", {config = 'vehicles/cardboard_box/large.pc', pos = vehPos, rot = vehRot}) end Here's the result: Sounds like you type it all in the console and execute it that way, but in my opinion, here's an easier way to do it for longer code: 1. Create a Lua file (lets say name it test.lua) in the BeamNG userfolder 2. Write your code there 3. And just execute the Lua file in the console using Code: dofile("test.lua")
How do I force the boxes to spawn at the 222,444,666 coordinates? When I spawn the first one, it spawns at the exact coordinates, but if I spawn the second one and more, they all spawn only next to each other. This is my code: Code: local offset = vec3(0, 0, 0) local x = 222 local y = 444 local z = 666 local vehPos = vec3(x, y, z) core_vehicles.spawnNewVehicle("cardboard_box", {config = 'vehicles/cardboard_box/large.pc', pos = vehPos, rot = vehRot}) I would also like to learn how to specify the angle at which the box spawns, because the rotation on spawn seems random with this code.
They spawn around it to avoid spawning inside of each other. I'm not sure if there's a way to force spawning at a specific position. About the rotation, I don't see your "vehRot" variable?
Do you know how to change the vehicle's position after it's spawned? I appreciate the reply, btw. --- Post updated --- i've found this script, but it's for Lua triggers. I can't make it work with consoleNG: Code: local function teleportPlayer(data) local vehicleName = data.subjectName if data.event == 'enter' and data.subjectName ~= 'scenario_player0' then TorqueScript.eval(vehicleName..'.position = "28.505 158.914 369.664";') end end
You can set the position in two ways. One is setting the position without resetting the vehicle which is (the rotation parameter is a rotation offset): Code: local pos = vec3(0,0,0) local diffRot = quat(0,0,0,1) local veh = be:getPlayerVehicle(0) veh:setClusterPosRelRot(veh:getRefNodeId(), pos.x, pos.z, pos.z, diffRot.x, diffRot.y, diffRot.z, diffRot.w) The 2nd one is setting the position and resetting the vehicle which is (rotation here is an absolute rotation): Code: local veh = be:getPlayerVehicle(0) local pos = vec3(0,0,0) local rot = quat(0,0,0,1) veh:setPositionRotation(pos.x, pos.z, pos.z, rot.x, rot.y, rot.z, rot.w)