public override void update(AICharacter character) { IGravityClient gravityClient = character.getEntity().getGravityClient(); KeysPressed keysPressed = character.getEntity().getKeysPressed(); RayInformation rayInformation = character.getEntity().getGravityClient().getRayInformation(); RayHitboxes rayHitboxes = gravityClient.getRayHitboxes(); gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 0.0f, layermask, false); gravityClient.getRayInformation().checkRaysBelow(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 270.0f, layermask, false); float minimalSpaceBetweenTileBelow = rayInformation.MinimalSpaceBetweenTileBelow; float topFrontDistance = (rayHitboxes.HitTopFront.distance * 0.9f); bool turned = false; gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 0.0f, layermask, true); keysPressed = turnIfWallIsNear(gravityClient, topFrontDistance, rayInformation.MinimalSpaceBetweenTileFront, keysPressed, out turned); if (!turned && (rayHitboxes.HitMiddleBelow.collider.tag.CompareTo("Slope") != 0)) { keysPressed = turnIfOnAnEdge(keysPressed, minimalSpaceBetweenTileBelow, character); } character.setKeysPressed(keysPressed); }
public virtual bool checkObjectHitsFloor(IGravityClient object_) { #if USE_3D_RAYS RayInformation3D rayInformation = object_.getRayInformation3D(); RayHitboxes3D rayHitboxes = object_.getRayHitboxes3D(); #else RayInformation rayInformation = object_.getRayInformation(); RayHitboxes rayHitboxes = object_.getRayHitboxes(); #endif rayInformation.checkRaysBelow(object_, 0.0f, object_.getTransform().eulerAngles.z + 270.0f, layermask); float correction = 0.0f; float minimalSpaceBetweenTileBelow = rayInformation.MinimalSpaceBetweenTileBelow; bool objectOnFloor = (rayHitboxes.DistanceBelow < minimalSpaceBetweenTileBelow * rayInformation.BelowTolerance) ? true : ((multiplyYVelocityDown * yFallDistance) > (rayHitboxes.DistanceBelow - minimalSpaceBetweenTileBelow)) ? true : false; if (objectOnFloor) { correction = -(rayHitboxes.DistanceBelow - rayInformation.MinimalSpaceBetweenTileBelow); moveEntity(object_, correction); } return(objectOnFloor); }
public bool moveEntityDown(IEntity entity, KeysPressed keysPressed, Gravity gravity, float movementSpeed) { IGravityClient gravityClient = entity.getGravityClient(); bool moving = false; #if USE_3D_RAYS RayHitboxes3D rayHitboxes = gravityClient.getRayHitboxes3D(); #else RayHitboxes rayHitboxes = gravityClient.getRayHitboxes(); #endif Vector3 angles = new Vector3(entity.getTransform().eulerAngles.x, entity.getTransform().eulerAngles.y, entity.getTransform().eulerAngles.z); #if USE_3D_RAYS RayInformation3D rayInformation = gravityClient.getRayInformation3D(); #else RayInformation rayInformation = gravityClient.getRayInformation(); #endif if (!keysPressed.up && keysPressed.down) { rayInformation.checkRaysBelow(gravityClient, 0.0f, angles.z + 270.0f, layermask); } bool isWalking = !entity.getGravity().isFalling() && !entity.getGravity().Jumping; float frontDistance = rayHitboxes.DistanceBelow; if (frontDistance > rayInformation.MinimalSpaceBetweenTileBelow) { if (!keysPressed.up && keysPressed.down) { moving = true; if (!entity.getRotateHorizontalMovement()) { Vector3 pos = entity.getTransform().position; if (angles.z > 90.0f && angles.z < 270.0f) { pos.y -= ((frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) < movementSpeed * Time.fixedDeltaTime) ? (frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) : movementSpeed * Time.fixedDeltaTime; } else { pos.y -= ((frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) < movementSpeed * Time.fixedDeltaTime) ? (frontDistance - rayInformation.MinimalSpaceBetweenTileBelow) : movementSpeed * Time.fixedDeltaTime; } entity.getTransform().position = pos; } gravity.Reset = false; } } return(moving); }
public bool moveEntityUp(IEntity entity, KeysPressed keysPressed, Gravity gravity, float movementSpeed) { IGravityClient gravityClient = entity.getGravityClient(); bool moving = false; #if USE_3D_RAYS RayHitboxes3D rayHitboxes = gravityClient.getRayHitboxes3D(); #else RayHitboxes rayHitboxes = gravityClient.getRayHitboxes(); #endif Vector3 angles = new Vector3(entity.getTransform().eulerAngles.x, entity.getTransform().eulerAngles.y, entity.getTransform().eulerAngles.z); #if USE_3D_RAYS RayInformation3D rayInformation = gravityClient.getRayInformation3D(); #else RayInformation rayInformation = gravityClient.getRayInformation(); #endif if (keysPressed.up && !keysPressed.down) { rayInformation.checkRaysTop(gravityClient, 0.0f, angles.z + 90.0f, layermask); } bool isWalking = !entity.getGravity().isFalling() && !entity.getGravity().Jumping; float frontDistance = rayHitboxes.DistanceTop; if (frontDistance > rayInformation.MinimalSpaceBetweenTileTop) { if (keysPressed.up && !keysPressed.down) { moving = true; Vector3 pos = entity.getTransform().position; pos.y += ((frontDistance - rayInformation.MinimalSpaceBetweenTileTop) < movementSpeed * Time.fixedDeltaTime) ? (frontDistance - rayInformation.MinimalSpaceBetweenTileTop) : movementSpeed * Time.fixedDeltaTime; entity.getTransform().position = pos; gravity.Reset = false; } } return(moving); }
public override void update(IEntity entity) { Gravity gravity = entity.getGravity(); KeysPressed keysPressed = entity.getKeysPressed(); IGravityClient gravityClient = entity.getGravityClient(); #if USE_3D_RAYS gravityClient.getRayInformation3D().checkRaysFront(gravityClient, 0.0f, entity.getTransform().eulerAngles.z + 0.0f, entity.getGravityClient().getLayerToIgnore()); #else gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, entity.getTransform().eulerAngles.z + 0.0f, layermask); #endif if (keysPressed.jump && (gravity.isStanding() || #if USE_3D_RAYS (gravityClient.getRayHitboxes().DistanceBelow <= (gravityClient.getRayInformation3D().MinimalSpaceBetweenTileBelow))) && #else (gravityClient.getRayHitboxes().DistanceBelow <= (gravityClient.getRayInformation().MinimalSpaceBetweenTileBelow))) && #endif entity.getJumpedReleased()) { IBehaviourStateFactory behaviourStateFactory = entity.getBehaviourStateFactory(); entity.setState(behaviourStateFactory.getJumpUpState(entity)); moveEntity(entity, keysPressed, gravity, entity.getMovementSpeed()); }
public virtual bool checkObjectHitsPlatform(float yModifier, IGravityClient object_) { #if USE_3D_RAYS RayInformation3D rayInformation = object_.getRayInformation3D(); RayHitboxes3D rayHitboxes = object_.getRayHitboxes3D(); #else RayInformation rayInformation = object_.getRayInformation(); RayHitboxes rayHitboxes = object_.getRayHitboxes(); #endif rayInformation.checkRaysTop(object_, 0.0f, object_.getTransform().eulerAngles.z + 90.0f, layermask); bool objectHitTop = (rayHitboxes.DistanceTop < rayInformation.MinimalSpaceBetweenTileTop) ? true : (yModifier > (rayHitboxes.DistanceTop - rayInformation.MinimalSpaceBetweenTileTop)) ? true : false; if (objectHitTop) { float correction = -(rayHitboxes.DistanceTop - rayInformation.MinimalSpaceBetweenTileTop); moveEntity(object_, correction); checkObjectHitsFloor(object_); } return(objectHitTop); }