Making a sprite bounce off a solid using 8direction movemen.

Get help using Construct 2

Post » Sat Dec 05, 2015 5:31 am

The player object/sprite moves with 8 directional movement, I want the player to bounce off solid objects, similar to how the bullet movement can, but I can't work it out.
Reversing the 8player movement works but isn't the right solution, the player should bounce off at an angle and keep its direction, not go back on itself.

Image

Download:
dl.dropboxusercontent.com/u/4044336/ss.capx
Any help appreciated, thanks.
B
5
Posts: 13
Reputation: 251

Post » Sat Dec 05, 2015 11:04 am

So how long would you like the player to not have control over his sprite?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 05, 2015 4:49 pm

Ideally they just bounce off and you can still control them the whole time.
B
5
Posts: 13
Reputation: 251

Post » Sat Dec 05, 2015 5:01 pm

I was asking, because if the player is pushing up-left, there couldn't be a bounce,..
Well, the bounce would be there, but would immediately be overwritten by the move up-left..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 05, 2015 5:12 pm

I've done this in Game Maker no problem, but that wasn't using 8 direction movement, was custom movement. So maybe I'll have to create something like that again.
After your post I understand 8dir movement a bit better, I need to to be able to carry momentum.
Thanks.
B
5
Posts: 13
Reputation: 251

Post » Sat Dec 05, 2015 5:15 pm

Well you could set vectorX and vectorY and have it subtract from that on key down or something..
But you might be better of using custom movement anyway..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 05, 2015 5:26 pm

Yeah custom movement seems like the better option for this. I've only just started with C2 but have used other software.
Thanks for your helps LittleStain.
B
5
Posts: 13
Reputation: 251

Post » Sat Dec 05, 2015 10:09 pm

@oos
You could also use the bullet behavior to handle the bounce:
https://dl.dropboxusercontent.com/u/542 ... _8dir.capx

For more precise bouncing you'll need to find the angle of the object hit.
Maybe something like this:
viewtopic.php?f=147&t=152906&p=964827&hilit=normal#p964827
B
87
S
29
G
89
Posts: 5,102
Reputation: 60,190

Post » Sun Dec 06, 2015 12:10 am

The file you linked was great until you try it from the top, you just get pushed through the wall instead.

Gonna look at this other topic now, thanks.

Just as a side note, how do I +rep people on here?

edit: the other example is good too, but breaks when I add 8dir movement to the player. Also seems overly complicated for what I wanna do, I'll only be working with blocks, no slopes or circles.
I'll keep messing around see if anything works, ty for your time.
B
5
Posts: 13
Reputation: 251

Post » Sun Dec 06, 2015 3:06 am

For the other example you'd have to tweak it to use the 8dir movement instead of what it uses now.

With just horizontal and vertical walls you could use the overlaps at offset condition to see if there's a wall next to it and just invert the X or y vector depending on which side a wall is. You could do it like the following. The first step would be to get the Sprite out of the wall, that is where custom movement is useful. On another note you could also compare the X and y velocity in addition to the wall detection, since you only need to bounce against walls you're moving toward.

Sprite overlaps wall
> Sprite: customMovement: push out of solid

Sprite: overlaps wall at offset (-1,0)
Or
Sprite: overlaps wall at offset (1,0)
> Sprite: set xvelocity to -self.xvelocity

Sprite: overlaps wall at offset (0,-1)
Or
Sprite: overlaps wall at offset (0,1)
> Sprite: set yvelocity to -self.yvelocity
B
87
S
29
G
89
Posts: 5,102
Reputation: 60,190


Return to How do I....?

Who is online

Users browsing this forum: Buggi, Carlafnt, Congrats2u, ijust8, Phoenixbowman, tetuan, tomquayle and 9 guests