1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Generic unity plugin

Discussion in 'SimTools Plugins' started by narthur157, Dec 16, 2015.

  1. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,282
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    49,199Coins
    Ratings:
    +5,093 / 18 / -0
    I believe the "SimpleUDPReciever" is a app to check that data is flowing correctly from your unity game.
  2. Spacebar

    Spacebar New Member

    Joined:
    Dec 15, 2017
    Messages:
    19
    Location:
    United States
    Balance:
    271Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    3DOF, 6DOF
    @PhilMassler also post your script... could be something obvious.
  3. PhilMassler

    PhilMassler New Member

    Joined:
    May 28, 2019
    Messages:
    5
    Balance:
    92Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    2DOF
    Which script should I include? The custom Simtools Plugin ?
    The problem is, that i can't patch a game i made in Unity, i don't think that this is due to the code i wrote but rather, because i did something else wrong in the process.

    Maybe someone who already got Unity to work with Simtools can give a very rough step-by-step guide on what to do at what point in time. I'd imagine that would not only help me but also a lot of other beginners.

    https://www.xsimulator.net/communit...ugin-for-simtools-2-0-api-documentation.9107/
    I feel like this documentation isn't really beginner-friendly as i am still struggling with it.
  4. Metaverum

    Metaverum Member Gold Contributor

    Joined:
    Jan 10, 2019
    Messages:
    36
    Balance:
    146Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF
    I managed to get Claudio's source code working and sending data to SimTools. If anybody can help me out with the mathematics of figuring out how to figure out surge, heave and sway, I'd much appreciate it. Once that's figured out, I can code it in Unreal blueprints and post it here.

    So here's the problem:

    I have an object in world space, X is the forward axis, Y is the right axis and Z is the up axis. When I move the object in the X direction, I get a surge value, positive or negative depending on how it's moved. Sway and Heave also gives me good values when I move the object left and right or up and down.

    Problem occurs when the object is rotated in the world space, so that it's forward vector changes. As such:

    Untitled1.png

    So when I move the non-aligned plane along its X-axis, you can imagine it moves along both X and Y axes in the world space.. resulting in both surge and sway, even though it should just have sway at that moment.

    I hope I explained this correctly, I can only access the world coordinates of the object and that is the way I can calculate acceleration, by checking its position between the last frame and the current frame. However whenever the forward vector isn't (1, 0, 0), this method fails. It needs some extra mathematics and some sort of calculation with the forward vector to figure out.

    Thank you very much @Dirty so far for your help. :)
  5. Dirty

    Dirty Well-Known Member Gold Contributor

    Joined:
    Oct 15, 2017
    Messages:
    744
    Occupation:
    All the way up front.
    Location:
    Germany
    Balance:
    7,905Coins
    Ratings:
    +877 / 3 / -0
    Hey :)

    yeah, let's continue our conversation here, as there might be people around who might be interested or able to help.

    These are the steps I recommended:

    1. For every frame you subtract the previous position from the current position. Always in world coordinates! That difference is a "Vector3" (I guess it's called a "Vector3" in Unreal as well?)
    2. Then you divide that vector by DeltaTime (frame duration in seconds). Now you have your inertial speed vector (ISV) in [m/s].
    3. Since you also did this on the previous frame, you can subtract the previous ISV from the current ISV. This difference is then also divided by DeltaTime (frame duration in seconds) and you get the inertial accelerations vector (IAV). It is in [m/s^2]
    4. Divide this vector by 9.81 to convert units to Gs.
    5. Add the gravity acceleration to this vector. I think it should be {0,1,0} in Unity or {0,0,1} in your project. Anyways, the positive "one" should be on the UP component. The resulting Vector3 is your world specific acceleration (WSA).
    6. Then project this vector onto your vehicles longitudinal, lateral and vertical axis. I mean onto your vehicles lon/lat/vert axis expressed in world coordinates. You only need to know the length of the resulting projections. 3 floats. There should be a function for that somewhere. I think it's called "change of basis". These three numbers form a new Vector3 of their own and that is your vehicle specific acceleration (VSA).
    7. These three numbers can be sent to the motion cueing cueing software to represent lat/vert/lon acceleration in [G]. It represents the translations a person would feel on the vehicle.
    ...the important part is step 6. This is where you convert world accelerations into local accelerations in the coordinate system of your vehicle!

    If you also want to get the vehicle specific angular rates (if your vehicle is pitching and rolling), you will have to compare each frame's quaternion with the previous frame's quaternion. I am certainly not an expert on quaternions, but basically for each frame the question is:
    "How do I express the current orientation in the previous frame's reference system?"
    Maybe someone with a better understanding of quaternions can say which quaternion operation you need to achieve this.

    If your vehicle does neither pitch nor roll, then (world) heading rate can be used as vehicle specific vertical angular rate (yaw rate) and maybe you don't even need to add the gravity vector.

    Dirty :)
    • Like Like x 2
    • Creative Creative x 1
    Last edited: Jun 9, 2019
  6. Metaverum

    Metaverum Member Gold Contributor

    Joined:
    Jan 10, 2019
    Messages:
    36
    Balance:
    146Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF
    I managed to come up with a solution of my own, I will be posting it shortly! I hope it's correct.
    • Like Like x 2
  7. Metaverum

    Metaverum Member Gold Contributor

    Joined:
    Jan 10, 2019
    Messages:
    36
    Balance:
    146Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF
    Ok so I had to go back to my days at university and bring out the trigonometry a little bit for this one :D And some common sense. :D I wrote the full blueprint code and get seemingly correct values in Unreal now. I can post the full code in Github if other members can confirm that this is an acceptable solution. If not, I'll do further fixes with your help and post the code then.

    I'll cut to the chase and try to explain it the best way possible. I'll explain it in a 2D coordinate system first, because the solution is exactly the same for a 3D coordinate system. So in my explanation, you only get the values surge and sway, since there is no up-vector for heave.

    1. Take the world space location of your vehicle, and take its forward and right vector.

    2. Move to next frame and take the new world space location of your vehicle.

    3. Find the difference between the new world space location and the world space location at the last frame. Then take its length, this will be the magnitude of your movement.

    4. Find the unit direction vector from your world space location at the last frame to the world space location at the new frame. Keep in mind that the order of this is important! It moves from the old frame to the new.

    5. Right now you need the 2 different angles. One will be between your forward vector and the unit direction vector. Other will be between your right vector and the unit direction vector.

    6. For the surge value of your vehicle, you will take the angle between your forward vector and the unit direction vector, and plug it into a cosine function. Then you will multiply this with your magnitude. This is your surge value.

    7. Do the same thing for sway, by plugging in the angle between your right vector and the unit direction vector into a cosine function and multiplying it with the magnitude. This is your sway value.

    8. In order to keep this logic going, before moving to the next frame, you have to save your new forward and right vectors. As well as saving your new location so that it can be compared with the location at the next frame. Then you repeat this logic! Simply move to the next frame and repeat from step 3.

    9. If you want to add heave, simply keep note of your up vector and do the same thing. Nothing changes in this logic except a few additional calculations for heave. Find the angle between your up vector and the unit direction vector, plug it into a cosine function and multiply it with the magnitude. That will be your heave value.

    I will write in the spoilers 2 simple examples showing that it provides correct output.

    Consider the origin at (0, 0) and the ship is looking forward in the Y axis, which makes its forward vector (0, 1) and its right vector (1, 0). And now consider the new location to be at (15, 0), so that the ship has moved 15 units to the right.

    Our magnitude is 15 and our unit direction vector is (1, 0). Angle between our forward vector and unit direction vector is 90 degrees. Angle between the right vector and the unit direction vector is 0 degrees (facing the same direction).

    Cos(90) is 0, this means surge is 15 * 0 = 0.. no surge has occurred at this movement (the ship simply went right).

    Cos(0) is 1, this means sway is 15 * 1 = 15.. so the entire magnitude of our movement went into sway (the ship only moved towards its right vector). So this makes sense so far right? :D

    Here's another example with different forward and right vectors.

    Consider the origin at (0, 0) and the new location at (15, 0).. but this time the ship will be looking diagonally at 45 degrees. This makes its forward vector (0.707, 0.707) and its right vector (-0.707, 0.707).

    Our magnitude and unit direction vectors are the same at 15 and (1, 0). Angle between our forward vector and unit direction vector is 45 degrees, which makes Cos(45) * 15 which is 10.6 for the surge. Same calculation brings us to Cos(135) * 15 which is -10.6 for the sway.

    As I wrote this, I started wondering why the addition of the absolute values of surge and sway, which is 21.2, for the second example exceeds the magnitude of 15. Then I started doubting if my solution is correct. :D I hope I can get some clarification on this one.
    • Like Like x 1
    Last edited: Jun 10, 2019
  8. Dirty

    Dirty Well-Known Member Gold Contributor

    Joined:
    Oct 15, 2017
    Messages:
    744
    Occupation:
    All the way up front.
    Location:
    Germany
    Balance:
    7,905Coins
    Ratings:
    +877 / 3 / -0
    What you have done is calculate the velocity along and perpendicular to the vehicle fwd. direction. If you want the accelerations (which I highly recommend!) take one more derivative of those values. Just divide the difference in velocity by the difference in time: ∆V/∆t

    That will be a much better indication for the forces felt on the vehicle.

    Other than that, it seems correct for a 2D-only application.

    Not sure if I'm being too pessimistic here, but this might be considerably trickier in 3D. For 2D it's fine.


    ...you certainly can! This is normal. The only thing you will have to check is: Does the square root of the "summed squares" match.

    (Vx^2 + Vy^2) = 1

    Unit vector:
    (0.707^2 + 0.707^2) =0.99984 ...close enough!

    Velocity vector:
    (10.6066^2 + 10.6066^2) = 14.99999 ...close enough!

    And this is just as valid in 3D: (Vx^2 + Vy^2 + √Vz^2) = 1

    Dirty :)
    • Like Like x 2
    • Agree Agree x 1
  9. Metaverum

    Metaverum Member Gold Contributor

    Joined:
    Jan 10, 2019
    Messages:
    36
    Balance:
    146Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF
    Yes this makes sense! Unreal gives me delta time at each frame so having this addition is quite easy! It shall be done. :D

    I believe I'm getting a correct output for 3D as well. I will let you know once I run the necessary testing.

    I believe we got close enough values because I missed some decimal points at my calculations and whatnot, but Unreal itself uses the exact values so it would always be as precise as it can be. In any case, these are so close enough that the user would never feel the error margin. :)

    I'm quite happy this works! I will have to test this in my simulator now, then I will be posting it in Github.

    One question remains however, how would we acquire traction loss? I figured difference in yaw between 2 frames is the obvious answer. What do you think?
    Last edited: Jun 10, 2019
  10. Dirty

    Dirty Well-Known Member Gold Contributor

    Joined:
    Oct 15, 2017
    Messages:
    744
    Occupation:
    All the way up front.
    Location:
    Germany
    Balance:
    7,905Coins
    Ratings:
    +877 / 3 / -0
    I have to admit, that after almost two years of reading on the forums here, I am still kinda clueless what people even mean when they speak of "traction loss" :) If someone cold explain this to me, I'd appreciate.

    As far as I can tell, when a vehicle looses traction it will result in a (often abrupt) transition from static friction to dynamic friction on the wheel contact points. But this will be reflected in the vehicle acceleration- and rotation-vector and should thus be displayed by a 6DOF rig.

    I heard people move their entire rig around a point on the front to cue a drifting back axle of the car,... but which parameter drives this mechanism is not clear to me.

    I'd also wonder what happens when you drive a front wheel drive on such a rig :)

    Cheers :)
  11. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,032
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,890Coins
    Ratings:
    +10,880 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Traction loss is an attempt to give a sense of what happens in oversteer, which itself has a number of causal forms:
    • lift-off oversteer
    • snap-oversteer
    • trailing-throttle oversteer
    • throttle off oversteer
    • lift-throttle oversteer
    In the simplest explanation the limits of grip are exceeded at the rear wheels. Even a front wheel drive car can experience oversteer.
  12. Metaverum

    Metaverum Member Gold Contributor

    Joined:
    Jan 10, 2019
    Messages:
    36
    Balance:
    146Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF
    I figured a difference in yaw divided by delta seconds would be enough but I am not sure.. here's a sneak peek of the blueprint so far. Kinda got messy at the end because I'm printing values to the screen but without that it's quite clean.

    6DOFUnreal.png
    Last edited: Jun 10, 2019
  13. Dirty

    Dirty Well-Known Member Gold Contributor

    Joined:
    Oct 15, 2017
    Messages:
    744
    Occupation:
    All the way up front.
    Location:
    Germany
    Balance:
    7,905Coins
    Ratings:
    +877 / 3 / -0
    Oh... the vehicle dynamics side of it is clear, it's just that I wonder what "parameter" determines whether this axis gets a signal on the rig.

    But in the end I think it comes down to using yaw rate with a high pass filter (?)

    Something else that might be interesting would be to use the current drift angle for that. It would have to be calculated though as I think it is not available for export in most games.

    Thanks,... Dirty :)
  14. Metaverum

    Metaverum Member Gold Contributor

    Joined:
    Jan 10, 2019
    Messages:
    36
    Balance:
    146Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF
    Here is the repository: https://github.com/Jemboy/simtools-unreal-integration

    You need Engine Version 4.18 to test this one, although to change it to a different engine version should be no trouble. I also used a plugin from the marketplace called Path Follow. Right now it is FREE on marketplace, and it will be free until the end of this month. Once you get it, it's yours forever so do it now! :D It basically allows an actor to follow a spline set by you. It helped me do the testing. If you don't have it, simply click "Okay" when Unreal gives you a prompt asking about disabling it. That's all. :)

    If you have any questions, you may ask here and I'll do my best to help.
    • Useful Useful x 2
  15. PhilMassler

    PhilMassler New Member

    Joined:
    May 28, 2019
    Messages:
    5
    Balance:
    92Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    2DOF
    So after i didn't get my Unity-Project to work with Simtools i went a few steps back and started from the beginning trying to get Claudio's example project to work. Everything went well, i built the game, and patched it. Now when i run the game, with the "Simple UDP-Receiver" i can see, that my game actually is sending the UDP-Packages perfectly fine. In the Simtools Game Engine it also says that the game is running, which i guess means that patching the game worked.
    Sadly the motors aren't doing anything. I haven't changed anything in Claudio's code, so i am hoping somebody knows what to do here. Maybe i have to change the Simtools settings somehow? Thanks for the help!
  16. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,032
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,890Coins
    Ratings:
    +10,880 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Can you please post pictures of all of your settings, including the Tuning Center, and explain what you have done in terms of setting things up on the SimTools end.

    I am presuming you are using a licensed version of SimTools, is that correct?
    • Like Like x 1
  17. PhilMassler

    PhilMassler New Member

    Joined:
    May 28, 2019
    Messages:
    5
    Balance:
    92Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    2DOF
    Yes i am using a licensed version. I will post screenshots of my settings on Friday, as i don't have access to the computer until then.
    • Like Like x 1
  18. PhilMassler

    PhilMassler New Member

    Joined:
    May 28, 2019
    Messages:
    5
    Balance:
    92Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    2DOF

    Today, when going over all settings in SimTools to take screenshots for advice, we found out that we had totally wrong settings in the Tuning Center. In fact before we read your comment, we hadn't even opened it up, so thanks for that!

    After we got the example project working, it was very easy to transfer it on our own Unity game. Even the telemetry data we sent turned out to feel very accurate right away.
    • Like Like x 3
  19. Aitor Perez

    Aitor Perez New Member

    Joined:
    Jul 30, 2019
    Messages:
    10
    Balance:
    107Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    2DOF
    Hi, I try to send Telemetry information by UDP from Unity using @Claudio Silva solution. In SimpleUdpReciever I recive the information, and i create the plugin whit SimToolsGamePlugin. In SimTools GameManager I can patch but in SimTools GameEngine I don't see anywhere where it shows. I can know if this is working whitout output hardware?
    I am new in this and my english is not the best.
    Sorry and thanks.
  20. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,032
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,890Coins
    Ratings:
    +10,880 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Are you using a licensed version of SimTools, as the demo version only works with the Live For Speed plugin.