Monday, August 22, 2022
HomeGame Developmentphysics - How do I keep away from getting caught on left/proper...

physics – How do I keep away from getting caught on left/proper sides of sphere mesh in 3D area utilizing the cross product vector formulation for slope motion?


For my present venture I am attempting to get my participant character to maneuver correctly up/down sloped surfaces/triangles in 3D area.

I’ve discovered modest success with the next code (with C and raylib: https://www.raylib.com):

playerFwd = (Vector3){0.0, 0.0, 1.0};
playerRig = (Vector3){1.0, 0.0, 0.0};

//playerTop is the floor regular of the present triangle the participant is standing on.
playerFwd = Vector3Normalize(Vector3CrossProduct(playerTop, Vector3Negate(playerRig)));
playerRig = Vector3Normalize(Vector3CrossProduct(playerTop, playerFwd));

//worst case A
if(playerTop.x >  0.99999)
{
    playerFwd = (Vector3){  0.0,  0.0, 1.0 };
    playerRig = (Vector3){  0.0, -1.0, 0.0 };
}

//worst case B
if(playerTop.x < -0.99999)
{
    playerFwd = (Vector3){  0.0,  0.0, 1.0 };
    playerRig = (Vector3){  0.0,  1.0, 0.0 };
}

//rotation matrix for the participant to face on the present floor correctly:
participant.remodel = (Matrix)
{
    playerRig.x, playerTop.x, playerFwd.x, 0.0f,
    playerRig.y, playerTop.y, playerFwd.y, 0.0f,
    playerRig.z, playerTop.z, playerFwd.z, 0.0f,
    0.0f,        0.0f,        0.0f,        1.0f
};

Drawback is especially after I transfer alongside the left/proper sides of the pattern sphere mesh. My participant object retains on getting caught on these sides, and I’ve to program in edge instances to permit the participant object to really transfer on surfaces with the floor regular vector (+/- 1.0, 0.0, 0.0).

You possibly can see the problem on this video I made hopefully demonstrating the issue utilizing the above code proper now: https://youtu.be/-Eb5BR9KqgQ

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments