How do I free a stuck sprite in a solid object

Get help using Construct 2

Post » Sat Jul 11, 2015 1:50 pm

Hi! The help file says you should not teleport or move solids so nothing can get stuck but if you have to enable/disable the solid behavior the Player can get stuck inside an object if it becomes solid when the Player collision box is inside. Does anyone know a Workaround to fix this? I tried to add something like "Middleclick to set Y Position of Player to Player.Y-10" to bring him on top of the object but this could be a Problem if he is stuck in a wall and should not go up (may get out of the Level this way). :roll:
B
53
S
16
G
6
Posts: 718
Reputation: 9,150

Post » Sat Jul 11, 2015 1:57 pm

Best workaround would be preventing it from happening alltogether..

The other way would be to add conditions for each possible unwanted situation..

Comparing either player position on overlap or maybe the boundingbox and moving some px in the desired direction untill overlap isn't happening anymore (this could offcourse be done within the same tick if wanted)..
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 Jul 11, 2015 8:05 pm

Right, but I don't think its possible to prevent it because its part of the gameplay and sometimes the Player sprite gets stuck. Maybe it works with last vector and moving the sprite in the opposite direction to free it? (never tried something like that)
B
53
S
16
G
6
Posts: 718
Reputation: 9,150

Post » Sat Jul 11, 2015 8:21 pm

Yeah, you could always use the OldX, OldY trick..
Should be something like this:

create three instance variables OldX, OldY and A

-sprite is overlapping
-- trigger once
> set A to : angle(sprite.x,sprite.y,sprite.oldX,sprite.oldY)
-- system every tick
> sprite move 5px at angle A

-else
sprite set oldx = sprite.x
sprite set oldy = sprite.y

- (event)
-- (sub-event)
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 » Tue Jul 14, 2015 2:07 pm

Hi. Thank you for your example!
I added the code with a small modification (only if sprite is visible) and will test it. So far it seems to work fine. :)
Image
B
53
S
16
G
6
Posts: 718
Reputation: 9,150

Post » Tue Jul 14, 2015 6:21 pm

Just a thing:
- The "Every tickt" from line 13 is not necesary. The upper condition is an "every tick" condition, so if you use the action "Move 5 pixels..." without the "Every tick" but in the same line 13 or 11, it should work the same way. It's weird to use "Every tick" inside an "every tick" condition, it can produce non expected results.
Lead developer at Octeto Studios

Visit our portfolio at: http://www.octetostudios.com/ :)

Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614

Post » Tue Jul 14, 2015 7:06 pm

GamerGon wrote:Just a thing:
- The "Every tickt" from line 13 is not necesary. The upper condition is an "every tick" condition, so if you use the action "Move 5 pixels..." without the "Every tick" but in the same line 13 or 11, it should work the same way. It's weird to use "Every tick" inside an "every tick" condition, it can produce non expected results.


Using an empty (sub)event is actually the same as every tick, so removing it would make no difference..
If you put the action in line 11 it will not work as expected the first tick, because the angle is not set yet..
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 » Tue Jul 14, 2015 7:13 pm

LittleStain wrote:
GamerGon wrote:Just a thing:
- The "Every tickt" from line 13 is not necesary. The upper condition is an "every tick" condition, so if you use the action "Move 5 pixels..." without the "Every tick" but in the same line 13 or 11, it should work the same way. It's weird to use "Every tick" inside an "every tick" condition, it can produce non expected results.


Using an empty (sub)event is actually the same as every tick, so removing it would make no difference..
If you put the action in line 11 it will not work as expected the first tick, because the angle is not set yet..


That is what I tried to say... the "Every tick" inside is worthless.
And you're right... only in the same line 13 without the "Every tick" should work the same way ;) I added the 11 line without reading the action before line 13.
Lead developer at Octeto Studios

Visit our portfolio at: http://www.octetostudios.com/ :)

Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614

Post » Tue Jul 14, 2015 7:24 pm

GamerGon wrote:
LittleStain wrote:
GamerGon wrote:Just a thing:
- The "Every tickt" from line 13 is not necesary. The upper condition is an "every tick" condition, so if you use the action "Move 5 pixels..." without the "Every tick" but in the same line 13 or 11, it should work the same way. It's weird to use "Every tick" inside an "every tick" condition, it can produce non expected results.


Using an empty (sub)event is actually the same as every tick, so removing it would make no difference..
If you put the action in line 11 it will not work as expected the first tick, because the angle is not set yet..


That is what I tried to say... the "Every tick" inside is worthless.
And you're right... only in the same line 13 without the "Every tick" should work the same way ;) I added the 11 line without reading the action before line 13.


To you and me it's worthless, for beginners it shows what the condition is (an empty event/condition can confuse some)..
Removing it makes no difference whatsoever..
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 » Tue Jul 14, 2015 7:35 pm

LittleStain wrote:To you and me it's worthless, for beginners it shows what the condition is (an empty event/condition can confuse some)..
Removing it makes no difference whatsoever..


Agree, but it doesn't mean that they can't understand it :)

About the position of the action... now that I think about it a little more @LittleStain, I'm pretty sure that lines 12 & 13 are not necessary executed secuencially because they don't belong to the same action and they are at the same place from the condition hierarchically speaking. Am I right @Ashley?
If this is right... placing the "Move 5 pixels..." in line 11 or 13 should be the same so it can cause the angle isn't know at right moment.
Lead developer at Octeto Studios

Visit our portfolio at: http://www.octetostudios.com/ :)

Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614

Next

Return to How do I....?

Who is online

Users browsing this forum: marc254 and 9 guests