Better way to go up/down slope based on yaw?

Posted by CyanPrime on Game Development See other posts from Game Development or by CyanPrime
Published on 2012-06-25T02:08:49Z Indexed on 2012/06/25 3:23 UTC
Read the original article Hit count: 257

Filed under:
|
|

Alright, so I got a bit of movement code and I'm thinking I'm going to need to manually input when to go up/down a slope. All I got to work with is the slope's normal, and vector, and My current and previous position, and my yaw.

Is there a better way to rotate whether I go up or down the slope based on my yaw?

Vector3f move = new Vector3f(0,0,0);
move.x = (float)-Math.toDegrees(Math.cos(Math.toRadians(yaw)));
move.z = (float)-Math.toDegrees(Math.sin(Math.toRadians(yaw))); 
move.normalise();

        if(move.z < 0 && slopeNormal.z > 0 || move.z > 0 && slopeNormal.z < 0){
            if(move.x < 0 && slopeNormal.x > 0 || move.x > 0 && slopeNormal.x < 0){
                move.y += slopeVec.y;
            }
        }

        if(move.z > 0 && slopeNormal.z > 0 || move.z < 0 && slopeNormal.z < 0){
            if(move.x > 0 && slopeNormal.x > 0 || move.x < 0 && slopeNormal.x < 0){
                move.y -= slopeVec.y;
            }
        }

        move.scale(movementSpeed * delta); 
        Vector3f.add(pos, move, pos);

© Game Development or respective owner

Related posts about java

Related posts about 3d