public void StartEating(MovableEntity movable, Vector3 direction) { Eating = true; currentlyEating = movable; JustAte = true; eatParticles.Play(); currentlyEating.Eat(my.position + direction); GameplayManager.instance.AddMove(new RecordableMove(currentlyEating, RecordableMove.eType.StartEating)); }
void ExecuteMove(Vector3 direction) { Vector3 initialPosition = my.position; Vector3 finalPosition = RoundPosition(initialPosition + direction); JustAte = false; bool readyToEat = Eating && direction == my.forward; if (Suspended && readyToEat) { JustAte = true; eatParticles.Play(); currentlyEating.Eat(finalPosition); } else { RaycastHit hit; if (Physics.Linecast(initialPosition, readyToEat ? finalPosition + direction : finalPosition, out hit, layerMask)) { if (!HandleCollision(hit.transform, direction)) { // if stuck on your head, your ears push you up if (ShouldRiseOnEars()) { if (Physics.Raycast(my.position, yAxis, out hit, 1, layerMask)) { MovableEntity movable = hit.transform.GetComponent <MovableEntity>(); print("movable above: " + movable); if (movable && movable.CanMove(yAxis)) { movable.Push(yAxis); // should check if not eating first (carrot could be stuck under ceiling) } else { return; } } else if (Eating && Physics.Raycast(my.position + my.forward, yAxis, out hit, 1, layerMask)) { MovableEntity movable = hit.transform.GetComponent <MovableEntity>(); if (movable && movable.CanMove(yAxis)) { movable.Push(yAxis); } else { return; } } OnEars = true; OnHead = false; ChangePosition(my.position, my.position + yAxis, timeToFall, yAxis); } if (readyToEat) { JustAte = true; eatParticles.Play(); currentlyEating.Eat(finalPosition); } else { return; // there's a wall blocking us } } } else if (Eating && !StandingUp()) { if (SameDirection(direction, my.forward) && Physics.Raycast(initialPosition + my.forward, -yAxis, 1, layerMask)) { // check if movable, if movable, push it return; // tu peux pas tourner t'as une carotte dans la bouche } else if (SameDirection(yAxis, my.forward) && Physics.Linecast(initialPosition, finalPosition + direction, out hit, layerMask)) { print("bump"); return; // do rotation, bump in wall then come back } } if (OnTheSides()) // les oreilles se plient pas sur le côté { if (SameDirection(my.up, direction) && Physics.Raycast(finalPosition, -yAxis, 1, layerMask)) { return; } else if (SameDirection(-my.up, direction) && Physics.Raycast(my.position + my.up, yAxis, out hit, 1, layerMask)) { MovableEntity movable = hit.transform.GetComponent <MovableEntity>(); if (movable && movable.CanMove(direction)) { // this wall check is gonna be annoying movable.Push(direction * 3); } else { return; } } } } if (Suspended && direction == -my.forward) { currentlyEating.StopEating(); StopEating(); EndMove(0 * zAxis); } else { ChangePosition(initialPosition, finalPosition, timeToMove, direction); } if (!Eating || (!StandingUp() && !JustAte)) { if (Eating) { currentlyEating.transform.parent = my; } Vector3 axis = new Vector3(direction.z, 0, -direction.x); Quaternion initialRotation = my.rotation; Quaternion finalRotation = Quaternion.AngleAxis(90, axis) * initialRotation; finalRotation = RoundRotation(finalRotation); ChangeRotation(initialRotation, finalRotation, timeToMove, direction); } if (Eating && !JustAte && currentlyEating.transform.parent != my) { currentlyEating.Push(direction); } if (currentlyEating && currentlyEating.FullyEaten) { StopEating(); } }