Collision, Gravity & Jumping

For questions about using Classic.

Post » Sun Oct 16, 2011 6:19 am

Hello everybody.

I've been looking around the forum for a few days, while battling with events, and havent yet found a solution. So now i'm turning to you in desperation, and hoping not to bother ya'll too much.

The deal is this: i'm working on a platformer, but instead of using the platform behaviou, (since it didnt allow me to worki the way i needed to) i decided to accomplish it via events. some might call this tedious, redundant, or needless, but i personally find it more effective, and to each their own.

So far, i have gotten the controls and commands correctly, some of the gravity, and some of the jumping. but i cannot get collision to work correctly

i would like to know First of all, how would you go about setting up a collision system via events?
   for example, my Gravity is a constant force of 8px in 90 [downwards] every 16milisecond. (and mostly 16ms is my basic unit of time for measurement) - unless there is collision with ground-type object.

however the object which is falling, ends up stuck somewhat IN the ground, which i guess means that the collision is being detected AFTER it has sunk into the ground.

i tried lowering the amount of downward pixels and time intervals proportionally, but this nevertheless made things just fall slower [though sometimes they did not sink]



so, how would you, with events:
        * set up Gravity
        * Set up Collition
        * set up Jumping



thanks to anybody who reads this, if i wasnt clear please just ask
B
6
S
1
G
1
Posts: 52
Reputation: 858

Post » Sun Oct 16, 2011 5:08 pm

What about the platform behavior doesn't do what you want it to?

As for custom collisions, put everything you want to push out of in a family, use the custom movement behavior on the player, and the push out of object action, with normal (slide) selected, and have that family selected as the object to push out of when the player overlaps the family.

You can probably do the gravity and jumping with custom movement too, or you could use normal events (set position and have x and y values that you add/subtract from for speed).
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Mon Oct 17, 2011 2:03 am

Try using the box 2d physics. It's much more fun:
http://www.scirra.com/forum/topic43788_post273940.html#273940

B
18
S
4
G
1
Posts: 413
Reputation: 2,512

Post » Mon Oct 17, 2011 9:50 pm

Thanks for the responses.
I've been trying to work it out and i thinking i got something.

Urled:
i checked the link but wasnt completely able to make out what you were referring to. i did check the stuff out, so thanks anyway.s


Arima:
thanks for your tip. it made perfect sense, however for some reason i couldnt get it to function correctly. however inspired by your tip i came up with a solution. that resolved collision and gravity

basically what i did was this:

:: C O L L I S I O N ::
-------------------------
+ System: Object.Bottom - Ground.Top Greater than 0
     -> System: Set global variable 'collision' to 0

:: G R A V I T Y ::
-------------------------
+ System: global('collision') Equal to 0
     -> System: Start loop "gravity" and run 1024 times

     + System: On loop "gravity"
     + System: Object.Bottom - Ground.Top Greater or equal 0
          -> System: Set global variable 'collision' to 1

     + System: global('collision') Equal to 0
     + System: [negated] Object (Pick) and Ground (Pick) are overlapping
          -> Object: Set Y to Object.Y + (1 * TimeDelta)


i'd like to upload an example, but i'm not sure how.

this seems to work pixel perfect, and at great speeds.
but i must confess i'm not quite sure of how it works,
i came up with it late at night after fiddling a lot,
and without a rested mind, so i might need cleaning up,
and perhaps could be optimized.
somehow lowering or rising the number of times the loop is repeated affects the gravity speed proportionally, but i'm not sure of what the pixel per frame or millisecond is. but i'd like to find out in order to control the rate.

also, i'm not sure of what the exact value of timedelta is supposed to be, is each time delta something like 16.666~~~ milliseconds?
B
6
S
1
G
1
Posts: 52
Reputation: 858

Post » Tue Oct 18, 2011 12:28 am

[QUOTE=superpowerjoe]

:: G R A V I T Y ::
-------------------------
+ System: global('collision') Equal to 0
     -> System: Start loop "gravity" and run 1024 times

     + System: On loop "gravity"
     + System: Object.Bottom - Ground.Top Greater or equal 0
          -> System: Set global variable 'collision' to 1

     + System: global('collision') Equal to 0
     + System: [negated] Object (Pick) and Ground (Pick) are overlapping
          -> Object: Set Y to Object.Y + (1 * TimeDelta)
[/QUOTE]
The second one is a redundant condition, you already compared 'collision'. In this scenario (without knowing the rest of your events) Object.Y will grow by 1 pixel per second (1 * TimeDelta) as long as 'collision' is 0.


[QUOTE=superpowerjoe]
also, i'm not sure of what the exact value of timedelta is supposed to be, is each time delta something like 16.666~~~ milliseconds?
[/QUOTE]
There is no exact value. Timedelta is a value expressing the time passed since the last tick (may also call it frame) in milliseconds. This time varies depending on how many events needed to be executed in the last tick, how many other processes took time (e.g. some access to the graphic card by a browser), etc.
So this value will be slightly different on each tick. But you can rely on the sum of TimeDelta. If your game runs with 60 fps, then adding TimeDelta 60 times will result to 1. And 1/TimeDelta will give you the actual framerate - but only valid for that time of moment.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Oct 18, 2011 2:12 am

[QUOTE=tulamide]
The second one is a redundant condition, you already compared 'collision'. In this scenario (without knowing the rest of your events) Object.Y will grow by 1 pixel per second (1 * TimeDelta) as long as 'collision' is 0. delta something like 16.666~~~ milliseconds?
[/QUOTE]

i thought so too! but my reasoning was to have one check [outside the loop] which triggered the loop, and one INSIDE the loop to keep checking in every turn whilst the loop ran. otherwise it would assume it to be 0 from before the loop started.

however, i tried toggling it off, and the object stopped one pixel late, sinking into the ground. when i turned it back on it worked fine.

also, referring to time delta, so if time delta is the time [in ms] between each frame. if it ran at 60FPS would it be safe to say that TimeDelta = 1 second / FPS. or 1/60 second? so as long as it were 60fps it would be 0.016~s. ??

i now uploaded the example.
Time Delta Gravity
B
6
S
1
G
1
Posts: 52
Reputation: 858

Post » Tue Oct 18, 2011 4:00 am

[QUOTE=superpowerjoe]
i thought so too! but my reasoning was to have one check [outside the loop] which triggered the loop, and one INSIDE the loop to keep checking in every turn whilst the loop ran. otherwise it would assume it to be 0 from before the loop started.[/QUOTE]
Ah, yes, that's right. It was just a confusing set of events, but it needs to check again, that's correct. Sorry about that.

[QUOTE=superpowerjoe]also, referring to time delta, so if time delta is the time [in ms] between each frame. if it ran at 60FPS would it be safe to say that TimeDelta = 1 second / FPS. or 1/60 second? so as long as it were 60fps it would be 0.016~s. ?? [/QUOTE]
No :)
The framerate is just an average value. You might get 60 frames per second in the end, but there is no guarantee, that every tick lasts the same amount of time. It rather is something like
f1: 15ms
f2: 18ms
f3: 13ms
f4: 11ms
f5: 16ms
etc.


[QUOTE=superpowerjoe]i now uploaded the example.
Time Delta Gravity [/QUOTE]
Couldn't download it. (dropbox error 403)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Oct 18, 2011 5:33 am

[QUOTE=tulamide]
The framerate is just an average value. You might get 60 frames per second in the end, but there is no guarantee, that every tick lasts the same amount of time.[/QUOTE]

i see, i guess that makes sense, it depends on how long it would take to compute before the next draw.
does it also mean that i have no way of setting a fixed rate of pixel per second with that method? or do you have any idea of how that would work?


[QUOTE=tulamide]
Couldn't download it. (dropbox error 403)[/QUOTE]

hmm, strange. i uploaded it to mediafire if you care to check it out.
http://www.mediafire.com/?m1cbepexdh4qn2d
B
6
S
1
G
1
Posts: 52
Reputation: 858

Post » Tue Oct 18, 2011 9:55 am

[QUOTE=superpowerjoe]
The deal is this: i'm working on a platformer, but instead of using the platform behaviou, (since it didnt allow me to worki the way i needed to)
[/QUOTE]


I am quite interested in what it is in particular that you are trying to achieve that the platform behaviour would impede.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Tue Oct 18, 2011 12:52 pm

@superpowerjoe

The dropbox download error is because you provided the private url instead of the public one.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,844
Reputation: 48,289

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests