x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Increase score gradually whilst holding an item in 2D platformer game

Hello,

I am developing a 2D platformer game in Unreal at the moment and I'm somewhat lost. What I have until now is 2 players that are able to move around the platforms and a camera that follows them (also pans in & out).

I would like to add an item to the game, let's say a ball that when a player collides with he 'picks it up'. Now, I won't have no animation for that or anything complicated - the player might as well just have a red outline whilst 'holding the item'. I want the score to progressively increase by, say 10 points each second while the player 'holds' the item. If the second player collides with the first player (that is currently in possession of the item), the second player 'steals' it and his score will increase by 10 pts a second instead - until the first player takes it back, and so on.

TL;DR -

2D Platformer with 2 players. Player 1 picks an item (collides with) and he gains score constantly. Player 2 collides with player 1, he 'steals' item and gains score points for himself, again, continuously - 2 SCORE BARS. And so on.

I do know how to script, say, a player picking up coins and increasing his score with each coin collected, but not this. Any sort of help would be greatly appreciated. Thanks!

Product Version: UE 4.17
Tags:
more ▼

asked Dec 21 '18 at 06:50 PM in Blueprint Scripting

avatar image

OutOfRehab
7 1 2 5

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

basically it's the exact same as picking a coin.

Though except of giving him "coin value" right away, you Set a Timer.

alt text

If you need to grant 10 points on hit, you just call "GrantPoints" right before you Set the Timer ;)

0.png (109.8 kB)
more ▼

answered Dec 21 '18 at 07:26 PM

avatar image

Evigmae
1.6k 7 3 8

avatar image OutOfRehab Jan 03 '19 at 12:53 PM

Hello and thank you for the quick answer.

I have managed to make both characters pick up the item, and when they do, they get 10 points. However, the player doesn't get 10 points every second because I don't have a 'GotItem' function (event?) to test if and which of the players is in possession of the item. How can I do that?

I have attached some screenshots.

Also, is there a way I can make Player_1 get the item from Player_2 when they collide? and so on and so forth. I'm thinking there must be a way to identify which of the players has the item at any point in time, and if he does, he gets 10 points each second. I'm not sure how I could do that do. Thank you in advance!

alt text

alt text

avatar image Evigmae Jan 03 '19 at 02:38 PM

Like I showed you on the initial answer i gave you, you need a an initial "got item" event or function, and a different "give score" event or function.

Because for the timer to run, there needs to be an event or function with that name on that actor.

Also, Timers can't call events or functions with parameters, like you do in the screenshot. Because the parameter will always return empty, so they don't do it.

ie: Do what I did and it'll work.

avatar image OutOfRehab Jan 03 '19 at 02:47 PM

Hey, I already did try to do what you did in the screenshot. Thing is I don't have none of your custom events and I barely have any clue how you got 'em. I don't have no 'GotItem', 'GrantPoints' or 'LostItem' customs.

avatar image OutOfRehab Jan 03 '19 at 03:07 PM

Ok I think I got it, sorry for being hardheaded. I followed your screenshot and then simply connected the 'GotItem' custom to my OnPickUp function. Now any Player that grabs the item gets 10 points / timehere. Thank you! Though, how do I tell that the player had lost the item?

When the 2 players collide the item must switch owners. Obviously that won't virtually happen, but when the 2 players collide the player that had the item stops scoring and the other player starts getting points. So on and so forth. So I guess I need 2 separate score systems, one for each player?

alt text

alt text

customs.png (151.4 kB)
onpickup-func.png (146.3 kB)
avatar image Evigmae Jan 03 '19 at 04:11 PM

create a hasItem boolean variable. Set it to true on GotItem. and to false on LostItem.

When colliding with other character, call LostItem on itself, and GotItem on the character it collided with.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question