private void InputSpawn() { RayCast frontRayCast = _moveWrapper.GetChild <RayCast>(1); RayCast frontGroundRayCast = _moveWrapper.GetChild <RayCast>(2); var frontGround = (Node)frontGroundRayCast.GetCollider(); string name = NameGetter.FromCollision(frontGround); //check the player requested a spawn on an empty tile above ground if (frontGround != null) { if (Input.IsActionJustPressed("ui_select") && !frontRayCast.IsColliding() && (name == "GridMap" || name == "pot")) { //spawn a flower in front of the player Spatial flowerInstance = (Spatial)_flowerPlatform.Instance(); flowerInstance.Translation = Translation + _moveWrapper.Translation + moveWrapper.SPEED * FacingVec(); GetParent().AddChild(flowerInstance); if (name == "pot") { ((moveWrapper)frontGround).planted = true; } } } }
//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); }