Setting vehicle velocity and rotation speed in Lua

Discussion in 'Programming' started by Bob Loblaw, Jan 26, 2020.

  1. Bob Loblaw

    Bob Loblaw
    Expand Collapse

    Joined:
    Jan 26, 2020
    Messages:
    3
    Is there a way to set vehicle velocity from Lua? I mean not just apply some force to the vehicle or throttle up, i mean straight up setting the velocity.

    I know there is a obj:getVelocity() method, so logically there should be a obj:setVelocity(), but this one either does something else rather than what it says on the tin, or i don't know how to correctly use it.

    If there is no such method, then is there a method to actually apply force to the vehicle (again, not through the wheels)?

    Same two questions for rotation.

    Any help would be greatly appreciated.
     
    • Like Like x 1
    • Agree Agree x 1
  2. Bob Loblaw

    Bob Loblaw
    Expand Collapse

    Joined:
    Jan 26, 2020
    Messages:
    3
    A bit of a bump.
    This is for the BeamNG multiplayer project (the most popular topic here).
    We currently just set the position of a vehicle to the new location when the data arrives. That works, but it's extremely wanky and jittery, also doesn't really allow for collisions.
    The ability to just set the velocity of the vehicle will help preserve the physics between the states so that collisions work and just overall prettiness of the experience.
    It's very strange, but the obj:setVelocity() method seems to do nothing, yet the console doesn't get angry that there is no such method, so i guess i just don't understand something crucial here. It may be connected that I'm inexpirienced when it comes to lua.
    Again, any help would be appreciated.
     
  3. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    1,409
    Hey :)

    Short answer, no you can't set node velocities (and not just because it's not exposed, but because it's technically not possible).
    Same goes for setting rotation, you cannot change rotation without causing a full reset.

    What you can do is apply thrust to individual nodes. Take a look at thrusters.lua for some example usage. (obj:applyForce)
     
    • Like Like x 1
    • Informative Informative x 1
  4. Bob Loblaw

    Bob Loblaw
    Expand Collapse

    Joined:
    Jan 26, 2020
    Messages:
    3
    Thank you, Diamodback, that was about the best answer I could hope for.
     
  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