captainPicard

Untitled

Oct 3rd, 2021
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. public Vector3 checkMovement(Vector3 offset){
  2.        
  3.         colliderBounds = col.bounds;
  4.         Vector3 topPositions = new Vector3(colliderBounds.max.x, colliderBounds.max.y, colliderBounds.max.z);
  5.         Vector3 bottomPositions = new Vector3(colliderBounds.min.x, colliderBounds.max.y, colliderBounds.min.z);
  6.  
  7.         float finalY = offset.y;
  8.         float inputY = offset.y;
  9.  
  10.         if(offset.y != 0){        
  11.             for(int x = 0; x < numberOfCastsX; x++){
  12.                 for(int z =0; z <numberOfCastsZ; z++){
  13.                     RaycastHit hit;
  14.                     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));
  15.                     if(Physics.Raycast(posToCheck, ((Mathf.Sign(inputY) == -1)?Vector3.down:Vector3.up),out hit, 20f, blockMovement)){
  16.                         Debug.DrawRay(posToCheck, ((Mathf.Sign(inputY) == -1)?Vector3.down:Vector3.up) * hit.distance , Color.red);
  17.                         float tempFinal = (hit.distance -0.01f) * Mathf.Sign(inputY);
  18.                         if(Mathf.Abs(inputY) + 0.1f > hit.distance -0.01f){
  19.                             finalY = 0f;
  20.                             Debug.Log("TRIGGERED");
  21.                         }  
  22.                     }else{
  23.                         Debug.DrawRay(posToCheck, ((Mathf.Sign(inputY) == -1)?Vector3.down:Vector3.up) * 5, Color.green);
  24.                     }
  25.                
  26.                    
  27.                 }
  28.             }
  29.         }
  30.         if(offset.x != 0){
  31.             for(int z = 0; z<numberOfCastsZ; z++){
  32.                 for(int y = 0; y <numberOfCastsY; y++){
  33.                     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)));
  34.                 }
  35.             }
  36.         }
  37.  
  38.         Vector3 finalOutput = offset;
  39.  
  40.         finalOutput.y = finalY;
  41.        
  42.         return(finalOutput);
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment