// Handles the movement from player input private void InputMovement() { Vector3 dir = new Vector3(); if (Input.IsActionJustPressed("ui_right")) { dir += Vector3.Right; _moveWrapper.RotationDegrees = new Vector3(0, 0, 0); } if (Input.IsActionJustPressed("ui_left")) { dir += Vector3.Left; _moveWrapper.RotationDegrees = new Vector3(0, 180, 0); } if (Input.IsActionJustPressed("ui_up")) { dir += Vector3.Forward; _moveWrapper.RotationDegrees = new Vector3(0, 90, 0); } if (Input.IsActionJustPressed("ui_down")) { dir += Vector3.Back; _moveWrapper.RotationDegrees = new Vector3(0, 270, 0); } if (dir != Vector3.Zero) { _moveWrapper.Move(dir); } }
//provides grid based movement and handles collision information public KinematicCollision Move(Vector3 relVec) { if (!_collisionLoaded) { return(null); } relVec *= SPEED; KinematicCollision collision = MoveAndCollide(relVec, testOnly: true); //don't move if it would cause a collision and return that collision if (collision != null) { //handle the collision Node collider = (Node)collision.Collider; string name = NameGetter.FromCollision(collider); switch (name) { case "bambooPlatformStatic": Spatial staticBody = (StaticBody)collider; if (staticBody.Translation.y != 0) { staticBody.Translation = Vector3.Zero; relVec += new Vector3(0, SPEED, 0); collision = null; } break; case "pot": moveWrapper colliderMove = (moveWrapper)collider; if (colliderMove.Move(relVec / SPEED) == null) { collision = null; } break; case "GridMap": case "flowerPlatform": break; default: GD.Print("Unhandled collision against " + name); break; } } //move if it wouldn't cause a collision if (collision == null) { Translation += relVec; if (planted) { var plant = (Spatial)plantRaycast.GetCollider(); if (plant != null) { plant.Translation += relVec; } else { planted = false; } } } return(collision); }