private KeysPressed turnIfOnAnEdge(KeysPressed keysPressed, float minimalSpaceBetweenTileBelow, AICharacter character) { IGravityClient gravityClient = character.getEntity().getGravityClient(); RayHitboxes rayHitboxes = gravityClient.getRayHitboxes(); if (gravityClient.isFlipped() && rayHitboxes.HitLeftBelow.distance > 1.0f) { keysPressed.left = false; keysPressed.right = true; } else if (gravityClient.isFlipped() && rayHitboxes.HitLeftBelow.distance <= minimalSpaceBetweenTileBelow) { keysPressed.left = true; keysPressed.right = false; } if (!gravityClient.isFlipped() && rayHitboxes.HitRightBelow.distance > 1.0f) { keysPressed.left = true; keysPressed.right = false; } else if (!gravityClient.isFlipped() && rayHitboxes.HitRightBelow.distance <= minimalSpaceBetweenTileBelow) { keysPressed.left = false; keysPressed.right = true; } return(keysPressed); }
protected virtual KeysPressed turnIfWallIsNear(IGravityClient gravityClient, float topFrontDistance, float minimalSpaceBetweenTileFront, KeysPressed keysPressed, out bool turned) { turned = false; if (!gravityClient.isFlipped() && topFrontDistance <= minimalSpaceBetweenTileFront) { turned = true; keysPressed.left = true; keysPressed.right = false; } else if (!gravityClient.isFlipped() && topFrontDistance > minimalSpaceBetweenTileFront) { keysPressed.left = false; keysPressed.right = true; } if (gravityClient.isFlipped() && topFrontDistance <= minimalSpaceBetweenTileFront) { turned = true; keysPressed.left = false; keysPressed.right = true; } else if (gravityClient.isFlipped() && topFrontDistance > minimalSpaceBetweenTileFront) { keysPressed.left = true; keysPressed.right = false; } return(keysPressed); }
public float checkRaysFront(IGravityClient gameObject, float yAangle, float zAngle, int layerMask = 0, bool ignoreSlope = false) { RaycastHit2D hitTopFront; RaycastHit2D hitMiddleFront; RaycastHit2D hitBelowFront; float distance = (gameObject.isFlipped()) ? -1000.0f : 1000.0f; float distanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayTopFront, distance, yAangle, zAngle, out hitTopFront, Color.green, layerMask + ((ignoreSlope)? 0 : (1 << slopeLayerNumber))) : checkRayFlipped(gameObject, posRayTopFront, distance, yAangle, zAngle, out hitTopFront, Color.green, layerMask + ((ignoreSlope) ? 0 : (1 << slopeLayerNumber))); float tmpDistanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayMiddleFront, distance, yAangle, zAngle, out hitMiddleFront, Color.green, layerMask + ((ignoreSlope) ? 0 : (1 << slopeLayerNumber))) : checkRayFlipped(gameObject, posRayMiddleFront, distance, yAangle, zAngle, out hitMiddleFront, Color.green, layerMask + ((ignoreSlope) ? 0 : (1 << slopeLayerNumber))); distanceFront = (distanceFront < tmpDistanceFront) ? distanceFront : tmpDistanceFront; RayHitboxes rayHitboxes = gameObject.getRayHitboxes(); if (rayHitboxes.HitMiddleFront.collider != null && rayHitboxes.HitMiddleFront.collider.tag.CompareTo("Slope") != 0) { tmpDistanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayBelowFront, distance, yAangle, zAngle, out hitBelowFront, Color.green, layerMask) : checkRayFlipped(gameObject, posRayBelowFront, distance, yAangle, zAngle, out hitBelowFront, Color.green, layerMask); rayHitboxes.HitBelowFront = hitBelowFront; if (rayHitboxes.HitBelowFront.collider != null && rayHitboxes.HitBelowFront.collider.tag.CompareTo("Slope") != 0) { distanceFront = (distanceFront < tmpDistanceFront) ? distanceFront : tmpDistanceFront; } } else { hitBelowFront = new RaycastHit2D(); hitBelowFront.distance = -1.0f; rayHitboxes.HitBelowFront = hitBelowFront; } rayHitboxes.HitMiddleFront = hitMiddleFront; rayHitboxes.HitTopFront = hitTopFront; rayHitboxes.DistanceFront = distanceFront; gameObject.setRayHitboxes(rayHitboxes); return(distanceFront); }
public float checkRaysFront(IGravityClient gameObject, float yAangle, float zAngle, int layersToIgnore = 0) { RaycastHit hitTopFront; RaycastHit hitMiddleFront; RaycastHit hitBelowFront; float distance = (gameObject.isFlipped()) ? -1000.0f : 1000.0f; float distanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayTopFront, distance, yAangle, zAngle, out hitTopFront, Color.green, layersToIgnore) : checkRayFlipped(gameObject, posRayTopFront, distance, yAangle, zAngle, out hitTopFront, Color.green, layersToIgnore); float tmpDistanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayMiddleFront, distance, yAangle, zAngle, out hitMiddleFront, Color.green, layersToIgnore) : checkRayFlipped(gameObject, posRayMiddleFront, distance, yAangle, zAngle, out hitMiddleFront, Color.green, layersToIgnore); distanceFront = (distanceFront < tmpDistanceFront) ? distanceFront : tmpDistanceFront; RayHitboxes3D rayHitboxes = gameObject.getRayHitboxes3D(); if (rayHitboxes.HitMiddleFront.collider != null && rayHitboxes.HitMiddleFront.collider.tag.CompareTo("Slope") != 0) { tmpDistanceFront = (!gameObject.isFlipped()) ? checkRay(gameObject, posRayBelowFront, distance, yAangle, zAngle, out hitBelowFront, Color.green, layersToIgnore) : checkRayFlipped(gameObject, posRayBelowFront, distance, yAangle, zAngle, out hitBelowFront, Color.green, layersToIgnore); rayHitboxes.HitBelowFront = hitBelowFront; if (rayHitboxes.HitBelowFront.collider != null && rayHitboxes.HitBelowFront.collider.tag.CompareTo("Slope") != 0) { distanceFront = (distanceFront < tmpDistanceFront) ? distanceFront : tmpDistanceFront; } } rayHitboxes.HitMiddleFront = hitMiddleFront; rayHitboxes.HitTopFront = hitTopFront; rayHitboxes.DistanceFront = distanceFront; gameObject.setRayHitboxes3D(rayHitboxes); return(distanceFront); }