//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); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { _moveWrapper = GetChild <moveWrapper>(0); }