How do I Animate an Object Using Lua?

Discussion in 'Programming' started by CrashHaven, Apr 12, 2024.

  1. CrashHaven

    CrashHaven
    Expand Collapse

    Joined:
    Nov 5, 2023
    Messages:
    22
    I want to animate a object using lua. I know this is possible because in the gambler 500 scenarios to simulate the trash being picked up. I want to make it so when you enter the lua trigger an object moves from one spot to another. Any help is appreciated!
     

    Attached Files:

    • BeamNGdrive-Update-V029-Focuses-On-The-Gambler-500.jpg
  2. stefan750

    stefan750
    Expand Collapse

    Joined:
    Sep 15, 2013
    Messages:
    21
    The code for animating the trash in the Gambler 500 scenarios is in the file BeamNG.drive\gameplay\missionTypes\scatterPickup\customNodes\scatterAnimatorNode.lua, it might be useful as a reference.
    But basically it just calls the setPosition() function on the objects every frame (in onPreRender) to move them along a path.

    This will not really work with objects that have collisions though.
     
  3. CrashHaven

    CrashHaven
    Expand Collapse

    Joined:
    Nov 5, 2023
    Messages:
    22
    I don't need it to have collisions, how could i make an object go from one coordinate to another animated?
    --- Post updated ---
    like a person going between three coordinates randomly.
     
  4. UN1T

    UN1T
    Expand Collapse

    Joined:
    Dec 23, 2023
    Messages:
    50
    I think, you mean props
     
  5. AlexKidd71

    AlexKidd71
    Expand Collapse

    Joined:
    Mar 16, 2022
    Messages:
    494
    I wo
    I would do the animation in blender and then start it with a trigger in BeamNG.
     
  6. NuclearKnight

    NuclearKnight
    Expand Collapse

    Joined:
    Nov 30, 2013
    Messages:
    78

    You need to use "setPosRot" function to move the object.

    If you are just doing something like a straightline, you need to make a function that receives a starting, and an end point. Then the function should just move it every frame update until it reaches your end point.

    Keep in mind this is a very simplified explanation, and you would need to do stuff like Lerping etc to make it appear smooth and not be jittery
     
  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