Find floor in CustomPlayerController

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Find floor in CustomPlayerController

Postby SFCBias » Sat Oct 15, 2011 8:12 am

I've been trying to work with the custom player controller and the CustomPlayerControllerSetVelocity wasn't working after looking over the tutorial code over and over. So I stepped through the source code a und found that the player controller never changed from freeFall state to on ground. I'm not 100% sure how the FindFloor function works so is there anything special I need to do to the body of the floor to make it be detected as the floor in the player controller?

Btw: The floor is just a simple static box.
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: Find floor in CustomPlayerController

Postby Julio Jerez » Sat Oct 15, 2011 10:36 am

if teh play is in freefall state it shoudl be calling this function

Code: Select all
void CustomPlayerController::PlayerOnFreeFall (dFloat timestep, int threadIndex)
{
   dFloat dist;
   dFloat hitParam;
   dVector velocity;
   dMatrix bodyMatrix;

   // Get the global matrices of each rigid body.
   NewtonBodyGetMatrix(m_body0, &bodyMatrix[0][0]);
   dVector posit (bodyMatrix.m_posit);

   dVector upDir (bodyMatrix.RotateVector (m_localMatrix0.m_front));
   dVector frontDir (bodyMatrix.RotateVector (m_localMatrix0.m_up));

   // make sure the body velocity will no penetrates other bodies
   NewtonBodyGetVelocity (m_body0, &velocity[0]);

   velocity = CalculateVelocity (velocity, timestep, upDir, m_stairHeight, threadIndex);

   // player of in free fall look ahead for the land
   dist = upDir % velocity.Scale (timestep);

   bodyMatrix.m_posit -= upDir.Scale (m_kinematicCushion);
   dVector floorNormal;
   dVector target (bodyMatrix.m_posit + upDir.Scale (dist));
   if (FindFloor (bodyMatrix, target, upDir, m_bodyFloorSensorShape, hitParam, floorNormal, threadIndex)) {
      // player is about to land, snap position to the ground
      bodyMatrix.m_posit = posit + upDir.Scale (dist * hitParam);
      NewtonBodySetMatrix (m_body0, &bodyMatrix[0][0]);

// look here
      if ((floorNormal % upDir) < m_maxSlope) {
         m_playerState = m_onIlligalRamp;
      } else {
         m_playerState = m_onLand;
         velocity = velocity - upDir.Scale (upDir % velocity);
      }
   }
   NewtonBodySetVelocity(m_body0, &velocity[0]);
}


in the funtion depending of teh value return by the call to FindFloor (bodyMatrix, target, upDir, m_bodyFloorSensorShape, hitParam, floorNormal, threadIndex))

if teh call return true then it will enet teh if branch and there i till change to state m_onLand if condition if ((floorNormal % upDir) < m_maxSlope) {
is not met.

check for the values of maxSlope, upDir, and floorNormal
my guess is that you have one of those misalligned.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Find floor in CustomPlayerController

Postby SFCBias » Sat Oct 15, 2011 11:10 am

Thats, the problem, FindFloor never returns true.
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: Find floor in CustomPlayerController

Postby Julio Jerez » Sat Oct 15, 2011 1:44 pm

Ok now you know, all you need to figure out is why findfloor is failing, and it should work.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests