Trouble with custom platform movement

For questions about using Classic.

Post » Sun Mar 20, 2011 8:12 pm

How do you make a platform character effectively jump, fall, and land using the custom movement behavior when using timedelta?

I've come up with like 3 different ways to implement gravity & pixel perfect landing, but every time I add timedelta it gets messed up (the player sometimes lands 1 pixel above the ground, hovers there for a bit, then falls down..or lands inside of the platform) I've tried collision offset, floor detectors, loops, and none of it works once timedelta is added.

I would greatly appreciate some help with this. I've already wasted all morning trying to figure this out :?
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Mon Mar 21, 2011 1:18 pm

Eh..? Should I post a .cap?
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Mon Mar 21, 2011 2:16 pm

Doesn't the Custom Movement behavior already use timedelta?
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » Mon Mar 21, 2011 3:39 pm

Sorry I was really tired when I made that post.

What I meant was "How do you make a platform character effectively jump, fall, and land using a custom platform movement and timedelta, or the custom movement behavior."

I've gotten the same results with both - player lands inside platforms or lands a pixel or two above platforms (preventing jumping) then falls down seconds later.

I tried using a loop in the same way you would for pixel-perfect or instant-hit bullets, but for whatever reason it has no affect.

I checked out other custom platform movements on the forums, but not a single one of them uses timedelta or the custom movement behavior, and the platform behavior is too wonky with low res games.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Mon Mar 21, 2011 4:41 pm

It's pretty hard to get the precision your looking for using timedelta, and collision detection.
If you want to go with your own movement I'd suggest not using collision detection at all, and just compare the x, and y values for everything.
Like if player y is greater than this, set .y to clamp(int(.y+ speed* timedelta),lowest y, highest y) for a fall.
Even then you might want to use the corner x, and y values, as just setting the hot spot to a corner may cause issues.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » Mon Mar 21, 2011 5:44 pm

I have tried and failed with this sort of thing also. A friend of mine made a little example for me yonks ago that I do not have anymore, but what he was doing was banking the timedelta value to a variable that was locked to whole numbers (abs() I think) and setting the movement off that variable.

Something along those lines anyhow.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Mon Mar 21, 2011 5:57 pm

I find it amusing how the smaller and more straightforward my games get, the more complicated it becomes to make them.

Anyway, I'm whipping up a .cap with a couple of the platform movements I've tried. Hopefully we can go over them and figure something out, because having problems making the most basic, low-res, framerate independent platform engine [size=50:2h8kjzyy]y'know, those things that have been around since '87[/size:2h8kjzyy] in Scirra Construct in the year 2011 is just..well, ridiculous. :wink:
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Mon Mar 21, 2011 7:03 pm

Ok here's the platform movement I came up with using the custom movement behavior. I managed to bring the problems I was having earlier to a minimum, but now I have some new questions.

Problem 1 is the player will occasionally land a pixel or 2 inside of the platform. I "fixed" it by using the "push out" action, but I'd like it to not go inside the platform at all. I know, I know, it's hardly even noticeable, but it's a still a bug, and it needs to go. *It's easier to see while moving, as the player will stop for just a second when it lands too far into a platform.

Also, you will see in event 2 that I round the player's x and y positions every tick. I did this because it results in smoother movements and scrolling, and is essential with such a small resolution. Problem is, now the player won't move at all when I use unlimited framerate mode. I'm not sure if this will be a problem for those with higher refresh rates, as I'll be using V-sync mode, so I thought I'd ask you guys about it.

Finally, take a look at the action in event 14. When entering a value for "Add to vertical speed" it says at the top that the value is in pixels per second, so I wouldn't need to add time delta to it right? Well, switch to unlimited framerate mode and note that jumping no longer works. If you change the 10 to something like 500*timedelta, then jumping works, but now landing is broken. What's up with that? It's as if the value for this action is NOT in pixels per second, as it states.

Anyhow, you can download the .cap HERE

Thanks for any help.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Mon Mar 21, 2011 9:21 pm

[quote:1hdneyrp]Problem 1 is the player will occasionally land a pixel or 2 inside of the platform.[/quote:1hdneyrp]
One solution would be to not use "Custom Movement" and just move the Sprite manually.
Use "overlapping at offset" to check if it will collide after the next move. If it doesn't, move it. If it does then do a loop moving 1 pixel at a time in the direction of motion until it is right against the obstacle.

[quote:1hdneyrp]Also, you will see in event 2 that I round the player's x and y positions every tick. I did this because it results in smoother movements and scrolling, and is essential with such a small resolution. Problem is, now the player won't move at all when I use unlimited framerate mode.[/quote:1hdneyrp]
Unlimited framerate makes tiny steps in position, which end up getting rounded away every tick.
For example.
say Player's X is 100 and horizontal speed is 50 pixels/sec.

newposition = oldposition + speed * time

Vsync 60 fps, time=1/60 sec
newposition = 100 + 50 * 1/60
=100.83 which rounds to 101

Unlimited ~ 900 fps, time=1/900 sec
newposition = 100 + 50 * 1/900
=100.05 which rounds to 100. No motion.



Here is your cap modified with a no behavior approach:
[url:1hdneyrp]http://dl.dropbox.com/u/5426011/examples4/nobehavior%20platform.cap[/url:1hdneyrp] made in 0.99.97
B
79
S
24
G
54
Posts: 4,743
Reputation: 40,749

Post » Tue Mar 22, 2011 12:01 am

Wow this is a great platform engine. Thanks a lot R0j0!

ONE MORE THING, then I'll never ask about platform engines ever again :wink: The reason I rounded the player's position is because it results in smoother movements and scrolling. For whatever reason, even though you rounded the player's position, it's movements and scrolling are still "jaggy". Swap the actions in event 32 and you'll see how much smoother it is. Again, this 'breaks' the platform engine when in unlimited framerate mode, so I'm assuming it might not work for some people. Is there anything I can do about this?
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests