Event-based movements & collisions

Get help using Construct 2

Post » Thu Nov 28, 2013 8:45 pm

Practically every CC/C2 user, including myself, has relied on the built-in behaviors for movements & collisions. Because of this (and delta time making your own collisions difficult) there are no examples or anything on how to create your own movements & collisions with events or even the custom movement behavior. The built-in behaviors are pretty good but they don't cover everything...

Anyway, what I'm trying to make is a "classic action/RPG" movement like those in Zelda:ALttP, Illusion of Gaia, Chrono Trigger, etc. In these games you can:

-Move in 8 directions at a set speed (no acc/dec)
-Move along diagonal walls (example)
-Move up horizontal stairs (example)

Does anyone know how this can be done?MadFactory2013-11-28 21:47:42
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Thu Nov 28, 2013 8:49 pm

Make some diagonal collision and you'll slide across/up it like that. If you want no acc/dec then set them to 0 in the behaviour properties.
B
47
S
17
G
82
Posts: 2,231
Reputation: 48,609

Post » Thu Nov 28, 2013 8:52 pm

The 8 directional behavior is pretty far off. It does not move against diagonal walls at all, and moves slower in ordinal directions than it does in cardinal directions. Also setting its acc/dec to 0 means it won't move at all..
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Thu Nov 28, 2013 9:06 pm

Ah I guess I was imagining platform behaviour. That moves well against angles. If you set the deceleration higher than acc it doesn't tend to gradually slow down, which I guess is what you were trying to achieve?
B
47
S
17
G
82
Posts: 2,231
Reputation: 48,609

Post » Thu Nov 28, 2013 9:47 pm

I would recommend adding the keyboard from the input plugins. you can find it by clicking insert new object, then scroll down to input and there you'll see the keyboard, click on this to add it into your project, then go into your event sheet or create a character control event sheet, It's very useful when adding lots of animation for your sprite. you can use this to assign custom key controls, for movement angle/stepping speed and even configure the animation to be played or frame to be displayed when a key is down. as for acceleration / deceleration, try setting them to low and see how it goes, I'm no expert on construct I'm learning too. I'm currently working on my first platform, solving problems as I go.
Hope this helps
B
2
Posts: 1
Reputation: 152

Post » Thu Nov 28, 2013 9:52 pm

*scratches head* I've been using CC/C2 for over 4 years man. I know lol. I'm just tired of relying on built-in behaviors and would like to start writing my own as I did in MMF and GM, but since CC/C2 use delta time it's not as easy and there isn't a single example on how to write your own collisions that aren't complete trash.
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Thu Nov 28, 2013 10:03 pm

Have you tried a combination of 'move at angle' and 'push out solid'? I think there are quite a few options for the direction pushing out and it works smoothly, so you may be able to achieve your desired result.

I am also interested in this, so let me know if you find anything. I'll have a try myself later too.
B
28
S
8
G
5
Posts: 429
Reputation: 7,007

Post » Thu Nov 28, 2013 11:14 pm

@MadFactory
If deltatime is holding you back then ignore it and do your motion without it and deltatime can be added later.

Anyway 8direction is simple enough to make with events. The main thing that's tricky is collision response or with those videos wall sliding. Here is a capx with the preliminaries of collision response.
https://dl.dropboxusercontent.com/u/5426011/examples20/event_motion.capx

It's incomplete as I ran out of time today. If you remove event 14 then it should basically work like the behavior. On a side note you can get motion with the behavior without acceleration or deceleration by setting them very high.

Anyway since you can't access the collision polygon from events you'll have to either make assumptions about the wall shape or devise a way to find approximately where the collision occurred and the angle of the side hit. One documented method floating around the internet is the separating axis theorem (or SAT). The only drawback is it's a bit lengthy and tedious to make with just events, although as a plugin it could be useful.

I'll try to finish the example up over the next few days.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Fri Nov 29, 2013 6:07 pm

Here's an updated capx:
https://dl.dropboxusercontent.com/u/5426011/examples20/event_motion2.capx
It will work with arbitrary collision polygons but the wall sliding works best when the edges are in increments of 45 degrees. I found I didn't need that complicated vector math so all the formulas are fairly simple.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Tue Dec 03, 2013 8:17 am

@R0j0hound Thanks man, this is pretty solid! Kind of confused by the collideCheck function though - I didn't know you could use them that way. Also what is the purpose of events 11 & 12? Removing them doesn't seem to change anything.MadFactory2013-12-03 08:37:49
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Next

Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 24 guests