Solved Get Position from Trigger Lua?

Discussion in 'Mod Support' started by Occam's Razer, Apr 14, 2018.

  1. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    After some recent discussion, I've gotten the hankering to create a proof-of-concept for a 'looping' level, wherein the player is teleported to the opposite side of the level after hitting one if its edges. To work seamlessly, however, the teleportation needs to only alter one of the player's coordinates, not all three.

    I've adopted the teleporter code from Nadeox's simple_map, but every attempt I've used to retrieve the vehicle's position has raised errors. Most of the code I use for that sort of thing is used in scenarios, but I'm trying to make this work in the level itself, so I'm not sure if the scenario code should be compatible.
     
  2. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    most things should work.
    On what do you need help?

    Post the code!
     
  3. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Here's the code I'm working with. It's not set up to do anything with the position information it gets from the player, but getPosition causes an error (nil value), so I haven't really had the need to write the rest of the code.

    Code:
    local function teleportPlayer(data)
    local vehicleName = data.subjectName
    local vehiclePos = vehicleName:getPosition()
    if data.event == 'enter' then
                TorqueScript.eval(vehicleName..'.position = \"-200 -200 0.05\";')
    end
    end
    
    return teleportPlayer
     
  4. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    Code:
        local vehObj = be:getObjectByID(data.subjectID)
        local vehiclePos = vehObj:getPosition()
        vehiclePos.y = vehiclePos.y + 50
        vehObj:setPosition(vehiclePos)
    
    only in LUA
     
    • Like Like x 1
  5. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Ah, I see. You need the vehicle's ID, not its name.

    The only issue that this code creates is that the first time this code is used, the vehicle resets both its position and orientation/momentum, so I'll have to see if I can augment the two scripts.

    nvm - happens with both scripts.
     
    #5 Occam's Razer, Apr 18, 2018
    Last edited: Apr 18, 2018
  6. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    when you move the position of one vehicle object, it will always us this new position as a respawn position
     
  7. bob.blunderton

    bob.blunderton
    Expand Collapse

    Joined:
    Apr 3, 2015
    Messages:
    3,290
    Hey I know this is old and a bump, I've noticed when a car is falling, and I freecam & move around and hit f7, it does exactly what you want - teleports the car keeping the momentum & trajectory.

    Just look up that code in the game itself.
    I'd like to know if you ever solved this one!
     
  8. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    the code in this post should work (it just teleport the car)
     
  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