Picking up item

Talk about making games.

Picking up item

Postby Rebenely » Fri Jul 03, 2015 4:53 pm

Hello,
What I want is for my character to pick up an item. No inventory just the item to be held by the character
I have three ideas on how to do it:
Code: Select all
Collision -> Script Editor -> button press -> Pick up item

The problem is I when I use getKeyState, I can long press the button and it will equip/throw the item. The solution I think is to simulate a keydown event in script editor without repetition.

Code: Select all
Key Down -> Script Editor -> Collision -> Pick up item

The problem here is I can't see any collision function that will check if two objects collide.

Code: Select all
Global Code -> bool colliding
Collision -> Script Editor -> colliding = true
Key Down -> Script Editor -> if(colliding) -> Pick up item

I have more problems with this one: I don't like having many global vars, How would I know what item I'm colliding with.

I need help how to pick up an item, and if you ask me I like the first one the best since it's the first thing that came to my mind. I am actually using it, but the long press problem is really an issue. And for the second one, I think it can be solved by a global var bool collider which I really don't like.

Thank you for reading this long post of mine.
User avatar
Rebenely
 
Posts: 16
Joined: Fri Apr 05, 2013 1:13 pm
Score: 1 Give a positive score

Re: Picking up item

Postby bat78 » Fri Jul 03, 2015 8:18 pm

  • A collision event could be called once as long as you don't change the option "Repeat this event" that defaults to "No".
  • You can check whether an actor is in collision with another actor on several ways. One way is to use a function dedicated for it:
    Code: Select all
    if(!CollisionFree(name, x, y))
    {
        // What to do if this actor collides another actor
    }

  • To have access to the player you are colliding with, you can use the "collide" actor variable as long as it is in a collision event.
    myactor -> Add -> Collision -> Of Actor: "Any Actor" -> Edit Action -> Script Editor:
    Code: Select all
    collide.transp = 1.0f; // This code will set the actor you have collision with to invisible.

  • Here is a demo for you of how I would do it:
    pickup test.zip
    (76.12 KiB) Downloaded 148 times

    It uses an array of Actor pointers to store the actors you have collision with. That way you can easily access all of those actors and do w/e you want with them so it obviously provides you a full control over the picked up items. Check the scripts and you will see how.
    Move forward with the right arrow key.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Picking up item

Postby Rebenely » Sat Jul 04, 2015 6:49 am

Thank you!
I just used the CollisionFree functions since it's just a single item, but the bag demo looks really useful. I might be using it someday.
User avatar
Rebenely
 
Posts: 16
Joined: Fri Apr 05, 2013 1:13 pm
Score: 1 Give a positive score

Re: Picking up item

Postby bat78 » Sat Jul 04, 2015 8:26 am

Rebenely wrote:Thank you!
I just used the CollisionFree functions since it's just a single item, but the bag demo looks really useful. I might be using it someday.


Yes, it is a base system of Game-Editor styled full inventory and picking up interplay.
Requires some Game-Editor knowledge.

If I had to improve it, I would start with:
- Stacking (Checking if two items are compatible by whether they share the same Actor settings and if so, removing them all and changing them to clones instead)
- Sorting (By clonename, by name (alphabetical), by turn etc)
- Replacing (for example last actor to come on the place of first - bag[0])
- Restrictions (only actors which name starts with "PICKUP_" could be picked up)
- Array sized with the number of "PICKUP_" actors loaded in the game.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron