Collision problem with time scale > 1

Get help using Construct 2

Post » Wed Sep 26, 2012 11:46 pm

Hi all

In my game I attempted to set the time scale to higher than 1. For example purposes, say I set it to 15 and have a 10x10 box moving from the left side of the screen to the right hand side, with a 5x5 box in the middle. It would appear that every tick the game would move the box 15 pixels to the right, teleporting it past any objects it might normally collide with at a time span of 1. In this example it causes the boxes to incorrectly not collide.

Is there a way to increase the time span and not break the collisions? If this simply isn't possible by increasing the time span, does anyone know of another technique to speed the game up? Or am I on the completely wrong path and this should be working?

Cheers
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Thu Sep 27, 2012 2:29 am

If you are using the physics behaviour, then i'd see if enabling 'bullet' mode in the properties would help. I don't know the details of it, but it basically gives the object more precise collision detection.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Thu Sep 27, 2012 2:41 am

No physics in there now, but I'll add it and the bullet behaviour and see if it helps.

Update: So I gave it a test and you are correct. The physics behaviour is not needed, but changing to the bullet behaviour does indeed collide with the object, regardless of the time scale.

Sample demo:
https://dl.dropbox.com/u/20830426/TimeScaleTest.capx

The unfortunate part is I'm trying to apply this to an object that also has the "Platformer" behaviour, and adding both the bullet and the platformer behaviour causes it to no longer collide. Anyone have any idea why bullet would work but platformer would not? Is this by design?boolean2012-09-27 03:06:59
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Thu Sep 27, 2012 12:45 pm

sorry, I don't have an answer but i am compelled to ask why you'd want to set the timescale so high?
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Thu Sep 27, 2012 4:56 pm

The time scale of 100 in the capx above was just for demonstration, to show that the bullet behaviour can collide correctly regardless of the time scale, but the platformer behaviour does not. In my actual game I'm trying get a 'fast forward' effect by setting the timescale to 5 or 6, but this has the same problem just on a smaller scale. Sometimes objects miss by a few pixels and go flying past :)
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Thu Sep 27, 2012 9:10 pm

They both miss for me, I think it's just a coincidence that the bullet behavior hits and the platform doesn't.

You have to manually check the positions the object moves over. You can do it by lerping from the old position to the new in a loop.

[code]
every tick:
+set newx to sprite.x
+set newy to sprite.y

repeat 11 times:
    +set sprite position to lerp(oldx,newx,loopindex/10),lerp(oldy,newy,loopindex/10)
is sprite overlapping wall:
    + do something

every tick
--or--
start of layout:
+set oldx to sprite.x
+set oldy to sprite.y[/code]
B
79
S
24
G
54
Posts: 4,743
Reputation: 40,749

Post » Fri Sep 28, 2012 1:37 am

Thanks R0J0hound, that does work. Good old lerp :)

I'm not sure how I would go about applying this to everything on screen. It works well when you just have one or two items, but gets complex fast when you try to speed everything up. Unless there is a scalable way of doing this I might just have to put this feature on hold.

It appears that some libraries like Box2D already take continuous collision into account (I assumed this was why the bullet behaviour was working because it implemented this), so it would be nice if this could be added to C2 Ashley if you are listening *bats eyelids*
B
24
S
4
G
1
Posts: 244
Reputation: 3,462


Return to How do I....?

Who is online

Users browsing this forum: WhosWho and 16 guests