Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Vector3 checkMovement(Vector3 offset){
- colliderBounds = col.bounds;
- Vector3 topPositions = new Vector3(colliderBounds.max.x, colliderBounds.max.y, colliderBounds.max.z);
- Vector3 bottomPositions = new Vector3(colliderBounds.min.x, colliderBounds.max.y, colliderBounds.min.z);
- float finalY = offset.y;
- float inputY = offset.y;
- if(offset.y != 0){
- for(int x = 0; x < numberOfCastsX; x++){
- for(int z =0; z <numberOfCastsZ; z++){
- RaycastHit hit;
- Vector3 posToCheck = new Vector3(colliderBounds.min.x + ((x+0.25f) * castSpacingX), (Mathf.Sign(offset.y) == -1)?colliderBounds.min.y:colliderBounds.max.y, colliderBounds.min.z + ((z +0.25f)* castSpacingZ));
- if(Physics.Raycast(posToCheck, ((Mathf.Sign(inputY) == -1)?Vector3.down:Vector3.up),out hit, 20f, blockMovement)){
- Debug.DrawRay(posToCheck, ((Mathf.Sign(inputY) == -1)?Vector3.down:Vector3.up) * hit.distance , Color.red);
- float tempFinal = (hit.distance -0.01f) * Mathf.Sign(inputY);
- if(Mathf.Abs(inputY) + 0.1f > hit.distance -0.01f){
- finalY = 0f;
- Debug.Log("TRIGGERED");
- }
- }else{
- Debug.DrawRay(posToCheck, ((Mathf.Sign(inputY) == -1)?Vector3.down:Vector3.up) * 5, Color.green);
- }
- }
- }
- }
- if(offset.x != 0){
- for(int z = 0; z<numberOfCastsZ; z++){
- for(int y = 0; y <numberOfCastsY; y++){
- placesToCastX.Add(new Vector3((Mathf.Sign(offset.x) == -1)?colliderBounds.min.x:colliderBounds.max.x, colliderBounds.min.y + ((y)* castSpacingY), colliderBounds.min.z + ((z +0.25f)* castSpacingZ)));
- }
- }
- }
- Vector3 finalOutput = offset;
- finalOutput.y = finalY;
- return(finalOutput);
- }
Advertisement
Add Comment
Please, Sign In to add comment