way to do if(x > x2) x = x2 with rotation?

Posted by CyanPrime on Game Development See other posts from Game Development or by CyanPrime
Published on 2012-06-25T18:32:51Z Indexed on 2012/06/25 21:24 UTC
Read the original article Hit count: 164

Filed under:
|
|

Alright, so I got this walking code, and some collision detection, now the collision detection returns a Vector3f of the closest point on the triangle that the projected position is at (pos + move), so then I project my position again in the walking method/function and if the projected position's x is > the nearest point'x the projected position's x becomes the nearist point's x. same with their z points, but if I'm moving in a different direction from 0 degrees XZ how would I rotate the equation/condition?

Here is what I got so far, and it's not working, as I go through walls, and such.

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

       // System.out.println("slopeNormal.z: " + slopeNormal.z + "move.z: " + move.z);

        move.normalise();
        move.scale(movementSpeed * delta); 

        float horizontaldotproduct = move.x * slopeNormal.x + move.z * slopeNormal.z;
        move.y = -horizontaldotproduct * slopeNormal.y;

        Vector3f dest = colCheck(pos, move, model, drawDist,  movementSpeed, delta); 
        Vector3f projPos = new Vector3f(pos);
        Vector3f.add(projPos, move, projPos);
        if(projPos.x > 0 && dest.x > 0 && projPos.x < dest.x) projPos.x = dest.x; 
        else if(projPos.x < 0 && dest.x < 0 && projPos.x > dest.x) projPos.x = dest.x; 
        if(projPos.z > 0 && dest.z > 0 && projPos.z < dest.z) projPos.z = dest.z; 
        else if(projPos.z < 0 && dest.z < 0 && projPos.z > dest.z) projPos.z = dest.z; 
        pos = new Vector3f(projPos);

© Game Development or respective owner

Related posts about java

Related posts about 3d