Announcement

Collapse
No announcement yet.

Measuring a vehicles relative acceleration?

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

    #16
    nm, I got it. Some strange stuff I'm doing though, I don't know if it's the best way to do this. In the TakeDamage function:

    Code:
    function TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector Momentum, class<DamageType> damageType)
    {
        local vector DirectionalHit, DirectionalFraction;
        local float RotationalYaw;
    
        DirectionalHit = ((HitLocation - Location) dot vector(Rotation)) * vector(Rotation);
        RotationalYaw = rotator(DirectionalHit).Yaw;
        RotationalYaw -= 16384;  // Head on collision = 0, collision from direct left = 16384, direct right = -16384.
        RotationalYaw /= 182;  // Approximate conversion to 360 degree scale.
        DirectionalFraction.X = cos(RotationalYaw);  // Gives me fractional values for each direction, which I can
        DirectionalFraction.Y = sin(RotationalYaw);  // multiply by the change in velocity to scale the magnitude of the hit.
    }

    Comment


      #17
      myDirectionalVel = (Velocity dot Rotation) * Rotation

      Seems like that should work to me. If the vehicle is going forward, then wouldn't myDirectionalVel be identical to absolute world coordinate velocity? Because Rotation would be pointing in the same direction as Velocity already! It is only when the vehicle goes backwards or is pushed sideways that you would see other results. myDirectionalVel was meant to be a vector in terms of world coordinates. You gotta have *some* frame of reference right? You still need to use the other equations after this one to get your final result . myDirectionalVel should just be a substitute for every occurence of "Velocity" in my first post. myDirectionalVel is just for handling the backwards/sideways motions nicely:

      Backwards will give a vector that is in the opposite direction of the Rotation, i.e.

      rotVec = vector(Rotation)
      rotVec/Vsize(rotVec) == -myDirectionalVel/Vsize(myDirectionalVel)

      that comparision should be true (they are pointing in the opposite directions) whenever the vehicle is driving backwards.

      For sideways motion, myDirectionalVel would be nearly (0, 0, 0).

      But when the vehicel is going forwards, myDirectionalVel should be idential to Velocity and thus iin woord coordinates still.

      Then you still gotta do the acceleration dot kungfu, as well as all the other kungfu you are doing to make nice readable numbers of course.

      Looks very interesting what you've done. My brain is still processing it .

      Comment


        #18
        :weird:

        I'm still trying to figure out what shes using it for, lol. My brain hurts, I think I need to lay down...

        Comment


          #19
          Heh. Well, I'm writing a 'plugin' for InMotion so you can play UT2004 on their motion simulators. Everything else was working fine, I was just having a small problem getting it to export a value for when you hit something or something hits you.

          This is the code I ended up with:

          Code:
          function TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector Momentum, class<DamageType> damageType)
          {
              local vector DirectionalHit, DirectionalFraction;
              local float RotationalYaw;
          
              DirectionalHit = ((HitLocation - Location) dot vector(Rotation)) * vector(Rotation);
              RotationalYaw = rotator(DirectionalHit).Yaw;
              RotationalYaw -= 16384;  // Head on collision = 0, collision from direct left = 16384, direct right = -16384.
              while(RotationalYaw > 32768)
                  RotationalYaw -= 32768;
              while(RotationalYaw < -32768)
                  RotationalYaw += 32768;  // Keep the number within range.
              RotationalYaw /= 182;  // Approximate conversion to 360 degree scale.
              DirectionalFraction.X = cos(RotationalYaw);  // Gives me fractional values for each direction, which I can
              DirectionalFraction.Y = sin(RotationalYaw);  // multiply by the change in velocity to scale the magnitude of the hit.
          
              // Calculate negative values manually.
              DirectionalFraction.X = abs(DirectionalFraction.X);
              if(RotationalYaw > 16384 || RotationalYaw < -16384)
                  DirectionalFraction.X = -DirectionalFraction.X;
              DirectionalFraction.Y = abs(DirectionalFraction.Y);
              if(RotationalYaw < 0)
                  DirectionalFraction.Y = -DirectionalFraction.Y;
          }
          This gave me 1 for X for a head on collision, and some fraction for X and Y for an oblique angle, and 1/-1 for Y for a direct left/right collision. X is negative for collisions from behind.

          Whew. :bulb:

          Comment


            #20
            :bulb: Nice work.

            Comment

            Working...
            X