WIP Beta released How do I teleport vehicles with triggers? Scroll down for the Zip

Discussion in 'Programming' started by HighDef, Apr 24, 2018.

  1. HighDef

    HighDef
    Expand Collapse
    Game Design, QA and burnouts.
    BeamNG Team

    Joined:
    Aug 4, 2013
    Messages:
    682
    I am working on a scenario where you have to drive up a slope whilst non AI dummy cars roll down the hill at you. I have a trigger box set up at the bottom where the dummy cars will contact and at that point I want the dummy car to be teleported back up to the top. I have been looking at the teleporting on Nadox1's Simple_Map but looking at the items.level.json..
    Code:
    {"name":"teleport_trigger_carreturn","class":"BeamNGTrigger","persistentId":"5147879f-1288-4ab6-b6cb-cc5df2e1c101","__parent":"teleports","position":[-20,10,0],"TriggerMode":"Contains","luaFunction":"local function teleportPlayer(data)\n    local vehicleName = data.subjectName\n\n    if data.event == 'enter' then\n        ui_message({txt=\"Teleporting to Skydome...\"})\n        TorqueScript.eval(vehicleName..'.position = \"-2000 250 75.5\";')\n        TorqueScript.eval(vehicleName..'.rotation = \"0 0 01 180\";')\n    end\nend\n\nreturn teleportPlayer","rotationMatrix":[1,0,0,0,0.9999997615814209,-0.0006905338959768414,0,0.0006905338959768414,0.9999997615814209],"scale":[6,6,6],"triggerColor":[9,255,0,45]}
    {"name":"teleporttext_skydome","class":"TSStatic","persistentId":"11cc6f55-01b5-4ef0-ab20-db5c1b7a6d1a","__parent":"teleports","position":[-20,10,0],"instanceColor":[0.8999999761581421,0.300000011920929,0.300000011920929,0.5],"scale":[3,3,3],"shapeName":"levels/simple_map/art/shapes/BBZ_teleport_skydome.dae","useInstanceRenderData":true}
    {"name":"teleport_1","class":"TSStatic","persistentId":"4aeb1b27-394e-4157-8644-fcb305094297","__parent":"teleports","position":[-20,10,0],"instanceColor":[0.8999999761581421,0.300000011920929,0.300000011920929,0.5],"scale":[3,3,3],"shapeName":"levels/simple_map/art/shapes/sr_teleport.dae","useInstanceRenderData":true}
    {"name":"teleport_trigger_carreturn","class":"BeamNGTrigger","persistentId":"1b76d9e9-20ff-4b52-ab36-c030885c4e34","__parent":"teleports","position":[-2055,250,63],"TriggerMode":"Contains","luaFunction":"local function teleportPlayer(data)\n    local vehicleName = data.subjectName\n\n    if data.event == 'enter' then\n        ui_message({txt=\"Returning to spawnpoint..\"})\n        TorqueScript.eval(vehicleName..'.position = \"-0 0 0.5\";')\n    end\nend\n\nreturn teleportPlayer","rotationMatrix":[1,0,0,0,0.9999997615814209,-0.0006905338959768414,0,0.0006905338959768414,0.9999997615814209],"scale":[6,6,6],"triggerColor":[9,255,0,45]}
    I am thinking that the teleporting is setup using Torque3D (editor).

    Does anyone have any experience with this? I would be very happy to learn the process. Thanks for your time.
     
  2. Nadeox1

    Nadeox1
    Expand Collapse
    Spinning Cube
    BeamNG Team

    Joined:
    Aug 5, 2012
    Messages:
    14,683
    Don't look at the json, but at the 'triggers' from the editor, easier to understand.

    You only need a 'BeamNG Trigger'.
    In the lua function you paste the same code I use for any of my teleport triggers, and adjust it to your preference (mainly the destination coordinates and message to print).
    That's it.
     
    • Agree Agree x 1
  3. HighDef

    HighDef
    Expand Collapse
    Game Design, QA and burnouts.
    BeamNG Team

    Joined:
    Aug 4, 2013
    Messages:
    682
    Ah, I see the process. I have it working now thanks. However there might be some bugs. Some of the cars are teleported with zero velocity and at the correct rotation an position that I specified, then some are teleporting but maintaining there speed and rotation factor. I would prefer them to maintain their current speed and heading.
    --- Post updated ---
    I am also getting further issues. After starting a fresh my docs folder and deleting all the repo mods I am getting problems after the first restart after the teleport has been used, shattered wheels and worse..

    As you can see, the effect is not any good if the vehicles teleport and are stationary. I am sure that this is useful for other things but is there a way to specify them to maintain velocity and heading? This would reduce the risk of teleporting inside of each other and would make for a more interesting experience I feel. Thanks again for your time.
    --- Post updated ---
    Here is what I am working with.

    https://drive.google.com/open?id=1HEl3BgSJIbQyEskNGIDbDEoETYYurTtY

    Perhaps it has something to do with the half pipe being stretched so much, maybe I should use many in a row rather than scaling one up to the length that I need.
     
    #3 HighDef, Apr 24, 2018
    Last edited: Apr 25, 2018
  4. HighDef

    HighDef
    Expand Collapse
    Game Design, QA and burnouts.
    BeamNG Team

    Joined:
    Aug 4, 2013
    Messages:
    682
    I have narrowed down the issue with shattered wheels and exploded physics, it happens when you restart after your car being teleported within another car and stuck together, resetting again once fixes some of it but I get weird noises and more bugging out, if I reset many times then it seems to be ok. It would be great if there was a way to cue the teleportations so they re-materialize once every few seconds.

    Here is some more footage
     
    #4 HighDef, Apr 25, 2018
    Last edited: Apr 25, 2018
  5. HighDef

    HighDef
    Expand Collapse
    Game Design, QA and burnouts.
    BeamNG Team

    Joined:
    Aug 4, 2013
    Messages:
    682
    Sorry if you are busy but do you have any insight on this at all please? Or is it a bug that I will have to wait to be fixed?
     
  6. Nadeox1

    Nadeox1
    Expand Collapse
    Spinning Cube
    BeamNG Team

    Joined:
    Aug 5, 2012
    Messages:
    14,683
    If you have two vehicles going through the trigger at the same time, they will get teleport in the same place together, meaning issues. Only way to avoid that is making sure they never enter the trigger together.
    For the rotation/momentum, that's pretty random.

    For the others issues, no clue as I never seen them (note I haven't tested the triggers much with other vehicles than the player one)
     
    • Informative Informative x 1
  7. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    I've toyed a bit with teleporting. The trick with momentum is that you can only set the vehicle's position, not its orientation. If you set the orientation to anything but what the vehicle's orientation was already set to*, the vehicle will reset, losing damage and momentum.

    *This usually results in vehicles being set to the same orientation repeatedly resetting only the first time.
     
    • Like Like x 1
  8. HighDef

    HighDef
    Expand Collapse
    Game Design, QA and burnouts.
    BeamNG Team

    Joined:
    Aug 4, 2013
    Messages:
    682
    You are a star! I removed the rotation specification and now they teleport as I want them too :) I just need to find out how to cue up the teleportations so that they don't spawn together. Thanks for your help.
     
    #8 HighDef, May 2, 2018
    Last edited: May 7, 2018
  9. HighDef

    HighDef
    Expand Collapse
    Game Design, QA and burnouts.
    BeamNG Team

    Joined:
    Aug 4, 2013
    Messages:
    682
  10. HighDef

    HighDef
    Expand Collapse
    Game Design, QA and burnouts.
    BeamNG Team

    Joined:
    Aug 4, 2013
    Messages:
    682
    #10 HighDef, May 13, 2018
    Last edited: May 16, 2018
    • Like Like x 2
  11. TheDiamondLord8

    TheDiamondLord8
    Expand Collapse

    Joined:
    Jan 2, 2017
    Messages:
    1,988
    I would suggest having the cars with more powerful engines, not modded. They look like they would struggle to get up the hill WITHOUT anything falling down.
     
  12. AshtheticPFX

    AshtheticPFX
    Expand Collapse

    Joined:
    Aug 4, 2017
    Messages:
    298
    I know this isn't my thread or anything, but it fits quite well. How do I get the co-ordinates for a teleport LUA?
     
    • Like Like x 1
  13. Nadeox1

    Nadeox1
    Expand Collapse
    Spinning Cube
    BeamNG Team

    Joined:
    Aug 5, 2012
    Messages:
    14,683
    Move your vehicle in the editor where you want it to 'teleport', and copy the coordinates from the sidebar (in Object Editor mode).
    Paste those coordinate in the trigger code.
     
    • Like Like x 1
  14. HighDef

    HighDef
    Expand Collapse
    Game Design, QA and burnouts.
    BeamNG Team

    Joined:
    Aug 4, 2013
    Messages:
    682
    The idea is that you select whatever car you want at this stage. I will be working on it for the rest of the week now I am on leave from work again. I am thinking of another map very similar but where you have a zig-zag road up the hill, where on each straight, you have to cross past the falling stuff. Also a Pigeon avalanche too.
    --- Post updated ---
    If you make anything that you think is good, please show us :)
    --- Post updated ---
    Ok, I just had a light bulb moment. If I make many triggers at the bottom that all have a slightly different position to teleport to at the top then there should be no more multi-spawn madness. I will have my work cut out now as the optimum way in my book is a grid of triggers like 1m2 large. I could use math to work out the coordinates of the positions so it shouldn't be too hard, just time consuming, but hey, I have 4 days off lol.
     
  15. AshtheticPFX

    AshtheticPFX
    Expand Collapse

    Joined:
    Aug 4, 2017
    Messages:
    298
    Look in my recent postings ;)
     
    • Like Like x 1
  16. HighDef

    HighDef
    Expand Collapse
    Game Design, QA and burnouts.
    BeamNG Team

    Joined:
    Aug 4, 2013
    Messages:
    682


    Many teleport triggers to help prevent the objects spawning inside of each other.
     
    #15 HighDef, May 17, 2018
    Last edited: May 17, 2018
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice