How do I fix and efficiently create a pick up & throw system

Get help using Construct 2

Post » Tue Sep 06, 2016 11:35 pm

Hello all! I'm trying to create a simple pick up and throw system. I made one but I'm having some issues. I also have some general questions about making a large game and C2 if any can help.

My problem: My player is throwing the box at downward angle. I want it to look like some simple NES looking throw. Something out of Duck Tales or Mario 2. I can't get the time for my events right. Am I doing this the right way? Also, how do create a pick up movement or animation, set moves the box from the floor to above the players head?

General questions: I plan to have many objects you can pick up. How would I do this? Would I make a family called Pickables (or whatever) and add all the sprites I can pick up in it? What if I wanted to make each Pickables to slow down the player or be thrown at a shorter or further distance? I know I would use a instance variables on the objects but how would I go about coding this? I know how I would manipulate travel distance and player speed for each pickable. How can I code this for family and the most effiecent way? I'm having problems understanding when and when I shouldn't use functions.

Image
Image

Thanks for looking at my post!
B
30
S
15
G
22
Posts: 183
Reputation: 14,221

Post » Wed Sep 07, 2016 12:42 am

I would start with:
When Box Picked up > Move Box negatively along the Y axis. Seeing as your players height will never change, this shouldn't be too difficult.

I remember in Mario 2 they used to snap the object to be infront of the player and then move it up and above the head.

Set your animations, like "Arms Up", if you have something like that.

Enable Pinned to Player. Set your "Carrying an Item" variable.

Then have an event where, if the player presses A, enable bullet movement and unpin on the carried object.
Have a sub-event, that will set the direction of the bullet based on the direction the player is facing. Facing Right set the angle of motion to 45 degrees, and facing Left to 135 degrees.

I would also disable collisions on the object once it has been thrown so that it falls off the screen. Then destroy it. You can handle enemy collisions (if you are using the object as a weapon) by checking for overlapping.
Unless you want to keep the objects you are picking up, for like building blocks or something.

Does that help?
B
56
S
15
G
13
Posts: 826
Reputation: 17,645

Post » Wed Sep 07, 2016 2:20 am

For picking up and throwing part, I have created two examples.

Throwing via Bullet

https://www.dropbox.com/s/l13oezvjoqyjw ... .capx?dl=0

Throwing via Physics

https://www.dropbox.com/s/tlaj11i5ewazg ... .capx?dl=0

heyguy wrote:1. How do create a pick up movement or animation, set moves the box from the floor to above the players head?


That's easy. When a box overlaps or in collision with Player, set Box's potision to Player's Imagepoint 1 (located above Player's head).

I would create an animation with arms up, as if the Player is holding a box nesting on his/her head.

For Super Mario Bros 2's throwing style, check out this thread.

how-do-i-make-super-mario-bros-2-styled-throwing-system_t150822

heyguy wrote:2. I plan to have many objects you can pick up. How would I do this? Would I make a family called Pickables (or whatever) and add all the sprites I can pick up in it? What if I wanted to make each Pickables to slow down the player or be thrown at a shorter or further distance? I know I would use a instance variables on the objects but how would I go about coding this? I know how I would manipulate travel distance and player speed for each pickable. How can I code this for family and the most effiecent way?


Please check out this tutorial by cacotigon. :mrgreen:

https://www.scirra.com/tutorials/556/un ... o-families
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Thu Sep 08, 2016 1:17 pm

@Tekniko @Gmoney Thanks a lot guys! This helped a ton! So I modified my throw events to work more like Gmoney's capx. Will modify this further with added functions, added variables and other goodies. I want items you can throw to be used as weapons, for puzzles and other sequences. This pink box specifically helps you reach a higher platform but this other throwable items can also hurt enemies as well.

So the throw works nicer but I now have a bug where eventually my character will start throwing the object in the opposite direction or just get stuck throwing it in one direction. Sometimes this bug will happen immediately, sometimes it'll take a few throws. Here are my events.

Image
Image
B
30
S
15
G
22
Posts: 183
Reputation: 14,221

Post » Thu Sep 08, 2016 5:23 pm

heyguy wrote:@Tekniko @Gmoney Thanks a lot guys! This helped a ton! So I modified my throw events to work more like Gmoney's capx. Will modify this further with added functions, added variables and other goodies. I want items you can throw to be used as weapons, for puzzles and other sequences. This pink box specifically helps you reach a higher platform but this other throwable items can also hurt enemies as well.

So the throw works nicer but I now have a bug where eventually my character will start throwing the object in the opposite direction or just get stuck throwing it in one direction. Sometimes this bug will happen immediately, sometimes it'll take a few throws. Here are my events.

Image
Image


You're welcome, heyguy..!! :mrgreen:

This method will correct the throw bugs.

https://www.dropbox.com/s/2djw1gykv1rft ... .capx?dl=0
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Thu Sep 08, 2016 5:59 pm

Thanks again for your help! I fixed it by doing this.

Image

Simple fix. I do have another issue maybe you or someone else can help me with related to this. I want the box (and any other throwable objects) to land flatly on the ground (tilemap). If it hits a wall, I want it to just fall straight down on the ground. Well...if I hit the tilemap anywhere other than the ground, the bullet disables and it stays stuck in the air.

If I do hit the ground, the box doesn't land directly "on" the ground. It's a few pixels inside the tilemap. Is there anyway to fix this, it looks a little sloppy. This issue is noticeable on the gif above.

I'm making a retro style pixel art game. I suspect that maybe making the box into a physics object might resolve this? Will that rotate the angle of the box if thrown? Can I restrict that? I want to maintain NES looking gameplay and system restrictions. And I'm making a mobile game so I don't want to tax the phone with any unnecessary resources.
B
30
S
15
G
22
Posts: 183
Reputation: 14,221

Post » Thu Sep 08, 2016 7:36 pm

You're welcome, heyguy. :mrgreen:

I have removed the 'bullet disabled' event from the event sheet, and added Box.Bullet.Speed / 5 on collision with walls.

https://www.dropbox.com/s/ghumj02vn62rm ... .capx?dl=0

For the thrown object's overlapping issue with tilemap, I would look into the object's set collision polygon to check first; after going into C2's image editor.

If everything is found to be correct there, then we'd need to investigate further. :mrgreen:
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Thu Sep 08, 2016 9:39 pm

One behaviour 4 everything. Including flying things.

https://www.dropbox.com/s/toa0mse2r2n8v ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Sep 08, 2016 11:01 pm

99Instances2Go wrote:One behaviour 4 everything. Including flying things.

https://www.dropbox.com/s/toa0mse2r2n8v ... .capx?dl=0


Wow! :o

I can never catch up with your advanced skills, 99Instances2Go. :mrgreen:

That's an amazing example. (e.g. Pick distance(BadOne.X,BadOne.Y,Player.X,Player.Y)) -> :o )
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Fri Sep 09, 2016 12:59 pm

He said that he wanted it to fall when colliding with the decor.

So, you got to handle 'the fall' and 'the push-out-of-solids'.

The fall (gravity wise) is very very easy with platform behaviour. (or physics)
And for the other 'thing', it is absolutly neccensary to not push it into solids. Platform behaviour is made for that. (so is physics)
But because there is allready a platform in play, i choosed platform above physics. This way the events stay in one and the same mind-world.

The push-out-of-solids is key in this story.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to How do I....?

Who is online

Users browsing this forum: Bobbyneal100, brunopalermo, mickclarke, mikehive, tinhofiel and 37 guests