[Solved] Keeping momentum when teleporting

Discussion in 'Programming' started by emlodnaor, Jun 28, 2022.

  1. emlodnaor

    emlodnaor
    Expand Collapse

    Joined:
    Apr 24, 2022
    Messages:
    11
    Hi, I'm having trouble making thePlayer keep it's momentum after teleportation...
    Currently the car resets without damage when teleported and also looses it's momentum.

    I've read some old post and watched some videos on how to set up a lua trigger and do teleporting, where they mentioned that rotation has to be off, but I have not added any rotation...

    Currently using this lua script in the trigger:
    Code:
    local function teleportPlayer(data)
        local vehicleName = data.subjectName
    
        if data.event == 'enter' and data.subjectName ~= 'scenario_player0' then
            TorqueScript.eval(vehicleName..'.position = "0 0 0.315";')
        end
    end
    
    return teleportPlayer
    Edit:
    Starting to think this is related: https://www.beamng.com/threads/f7-resets-car.86522/

    Old thread, and video:
    https://www.beamng.com/threads/how-...-with-triggers-scroll-down-for-the-zip.54376/
     
    #1 emlodnaor, Jun 28, 2022
    Last edited: Jun 28, 2022
  2. emlodnaor

    emlodnaor
    Expand Collapse

    Joined:
    Apr 24, 2022
    Messages:
    11
    I think I need to use "setPositionNoPhysicsReset" instead of "position", as there seems to have been an update, and a reset is now the default. However, I'm new to lua, and not sure how to implement it correctly... trying to change it out I get errors...
     
  3. emlodnaor

    emlodnaor
    Expand Collapse

    Joined:
    Apr 24, 2022
    Messages:
    11
    Have this now, and it seems to be working...
    Code:
    local function teleportPlayer(data)
        if data.event == 'enter' then
            pos = Point3F(0,0,0.277)
            cow = scenetree.findObject(data.subjectName)
            cow:setPositionNoPhysicsReset(pos)
        end
    end
    
    return teleportPlayer
    --- Post updated ---
    What i'm lacking with this is moving the camera too, it does not stay in the same place relative to the car... this is not a big problem when I teleport in the same direction as i'm already moving, but when I teleport behind myself, the camera first shows the front of the car, then spins around to the back...

    Any tips on how to do that would be greatly appreciated :D
     
    • Like Like x 1
  4. Artistterrymartin

    Artistterrymartin
    Expand Collapse

    Joined:
    May 5, 2019
    Messages:
    710
    Hahaha, that is my video... I noticed too that things are not keeping momentum. Thanks for updated LUA for those wanting to keep momentum it seems after some recent update.
    I do not know LUA, I copied pasted from someone else. I tried to teach myself watching YouTube videos but caught a case of acute narcolepsy lol. Ever have trouble sleeping, watch a how to program LUA tutorial. They are almost as boring as my tutorials :p
     
  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