Pickup object on key press when next to it

Stats

1,850 visits, 2,798 views

Translations

This tutorial hasn't been translated.

Tools

So like most RPG type games, there are pickups involved. There is a problem involved when there are multiple objects in quite a small space.

This can easily be fixed by having a collision box that follows your player. If you set the player sprite to pickup bottles without a pickup collision box, you will run into certain problems. But if you have a uniform surface, it makes is a lot easier to manage.

To do this, it's pretty straight forward.

Firstly set up your layout how ever you want it.

I have some debug text, a keyboard object, a player and an object (which is solid) that will randomly spawn (tutorial).

Now all you need to do is create a blank sprite that is just bigger than your player.

In this example, I named it PickupCol and made it fairly small.

That's basically all you need for the layout editing.

Move to your event editor and do the following.

What is happening?

It detects whether the rubbish object is within the the PickupCol object, and if the space bar is pressed. If both events are true it will move onto the sub event.

The sub event picks the nearest to the player and deletes it, and adds 1 point to rubbish. The reason why it isn't closest to the Pickup box is because there could be multiple pickups in the box.

You can add direction and animation in to make it more dynamic. Direction as in, if you're facing left, you don't want to be picking up objects on your right.

Direction

As requested in the comments below:

To add direction add another condition that checks if the player is facing left or right, but since there is no condition that does this we have to do it ourselves.

The are a few ways to do this, but two of the most best ways to do this are as follows:

Make two collision boxes that check for left and right respectively, and just fill in the event sheet as you see fit (Add another condition block for the right box, then alter the current conditions for the left box)

Or you can use one collision box but use more events.

(More on this once I get back to my computer)

Anyway, that should be all. Hope it helps.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!