Solved Be:vehicle setPosition & setRotation

Discussion in 'Mod Support' started by Neo, Jul 7, 2018.

  1. Neo

    Neo
    Expand Collapse

    Joined:
    Oct 31, 2015
    Messages:
    262
    Hello there,
    I am writing a custom vehicle spawner for my spike strip mod. The goal is to spawn a spike strip behind a car. So far that works already with the "spawn.spawnVehicle()"-function, but it is not so fluid enough. The spawning process takes some time and pauses the game for a second. So I came up with the idea that I could spawn the spike stip once and then only set the position and the rotation but here begins the trouble. I could not find a "setRotation"-function and the "setPosition"-function does not accept, due to a type mismatch, my calculated position:(

    The ready to use script is in the appendix with the problem lines commented out (spikestrip\lua\ge\extensions\bluetac\spikestrip.lua).

    If you have another idea to make the process more fluid, tell me ;)
     

    Attached Files:

    #1 Neo, Jul 7, 2018
    Last edited: Jul 7, 2018
  2. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    I don't think that setRotation() is a real thing for a vehicle. Instead try vehicleSetPositionRotation(id, px, py, pz, rx, ry, rz, rw) or something like scenetree.findObject('thePlayer'):setPositionRotation(px, py, pz, rx, ry, rz, rw)

    As you can see, you'll need to break up that quaternion into individual values to punch them into the function. Since you've got the quaternion in the variable rot you can use rot.x, rot.y, rot.z, rot.w for the last 4 values in the function.
     
    • Informative Informative x 2
    • Agree Agree x 1
  3. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    Some function to help you
    Code:
    quatFromEuler(0, 0, math.rad(90))
    
    -- Need 0.12 for the getDirection* function
    -- `pv` is the vehicle object
    local dir = vec3(pv:getDirectionVector()):normalized()
    local up = vec3(pv:getDirectionVectorUp()):normalized()
    quatFromDir(dir, up)
    as @torsion pointed out, `setRotation` doesn't exist you have to use `setPositionRotation`
     
    • Informative Informative x 2
  4. Neo

    Neo
    Expand Collapse

    Joined:
    Oct 31, 2015
    Messages:
    262
    @torsion Thank you, setPositionRotation() works :)
    and thank you @thomatoes50 for providing additional informations:)

    But may I ask two more questions? Where can I find the beamengine methods? And where do you know that @torsion?
     
  5. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    Most probably, he read a lot of code from the game to know what we are using and how.

    everything that start with `be:` is beamengine methods, you can search those using a text editor
     
    • Like Like x 1
  6. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    thomatoes50 is correct. I've spent quite a bit of time reading Lua code from the game. I also do a lot of searching inside the official code in order to find what I want.

    I prefer to use Agent Ransack to locate useful sections and then Notepad++ to read it. Agent Ransack is also great because it displays 1-line snippets of your matches, so you can quickly see how a function is called.

    EDIT: I forgot to say you're welcome, and good luck with the mod.
     
    • Like Like x 1
    • Informative Informative x 1
  7. Neo

    Neo
    Expand Collapse

    Joined:
    Oct 31, 2015
    Messages:
    262
    Thank you ;) and also thanks for the tipp with Agent Ransack. I will try it out. Currently I´m using Atom for searching.
     
  8. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    Let me know what you think after you try it out. I've been using Agent Ransack for years, but I never compared it with other search utilities. If there's something better I'd like to know. :) To see the grep-like 1-line snippets be sure that the window is big enough. At a large enough size the window will display a pane on the left with file results and a pane on the right with all matching lines from the selected file result.
     
    • Like Like x 1
  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