Announcement

Collapse
No announcement yet.

[Solved] Axis specific Velocity Reduction - issue possibly in setLinearVelocity/math/local global

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Solved] Axis specific Velocity Reduction - issue possibly in setLinearVelocity/math/local global

    Hi. I have an actor with a physical body. I apply forces to it and I want to "simulate" drag. I tried to getLinearVelocity, transform it into actors coordinates, *modify it, transform it back, and setLinearVelocity back.
    This afaik completely works, if I modify it as a whole (lerp to (0,0,0) vector).

    But when I try to lerp x, y, z with different rates, it works only if I don't spin my ship. When I try to spin more aggressively, I am able to completely change my direction (more than 90° - which should be impossible).

    Blue arrow is the original linear velocity, the red/green arrow is the current linear velocity. This is how it is supposed to work all the time:
    Click image for larger version  Name:	works2.png Views:	0 Size:	106.7 KB ID:	1804176
    You can see how it reduces local Y velocity and keeps local X velocity. (Video 20-30s here https://youtu.be/p-MFSjqyUEI?t=20)

    But when I heavily rotate (and only with different values per axis), I am pretty easily able to produce 'impossible' state:
    Click image for larger version  Name:	Broken3.png Views:	0 Size:	73.0 KB ID:	1804177
    It should be impossible to reduce the blue vector to the red one, yet this happens.

    My code is this (box is the root of the actor) and works if I set all the alphas to the same value:
    Click image for larger version  Name:	broken.png Views:	0 Size:	203.7 KB ID:	1804179
    (yaw control here):
    Click image for larger version  Name:	yawCtrl.png Views:	0 Size:	83.9 KB ID:	1804180


    You can see the problems in the video here, at 50s mark: https://youtu.be/p-MFSjqyUEI?t=50

    I've tried pretty much everything I could think of, but I didn't solve it yet. Could anyone help me, please? I struggle with it for quite some time now, which is why I have that ground texture, these arrows etc. I am unable to understand why this keeps happening.
    Attached Files
    Last edited by Gonzi; 08-23-2020, 08:46 PM.

    #2
    Update: I've added debug box (the current linear velocity should not be able to escape said box), yet is does just that with ease. I've tried to use AddForce instead of changing the velocity directly, I've tried to add two forces separately for each axis, I've rewired the control logic so that I can be sure of the order of it happening, yet the problem still persists.

    You can see how the velocity, that should just be reduced leaves its possibility space:


    What am I doing wrong? I don't get it. At all

    Comment


      #3
      And I've found the culprit:
      Click image for larger version

Name:	SmartSelect_Squid.jpg
Views:	59
Size:	271.8 KB
ID:	1804782
      The issue was that each tick, the ship could be rotated differently, so the possibility space of the reduced vector changes. Violet velocity shows how previously impossible future velocity becomes possible, so with the optimal ship rotation, I am able to turn the vector fully around.

      The sad thing is, that this actually isn't an issue. It should act exactly like that. Car moving South will move north if only steering will be applied. It just seems counterintuitive - possibly because you could do things like these only in extreme cases, like with a car, where the sideways slowdown is incredibly high, but the forward slowdown is almost non-existent at lower speeds).

      Comment

      Working...
      X