![]() |
Flush wall detection
I'm messed around with walking systems before... but I figure I could learn something that still boggles me.
I've tried walking systems, and of course the hardest part is the wall detection... so my question is, how can you make a flush wall detection? By flush I mean, as you run into a wall, you walk flush into it, not 3 pixels away, not 2 pixels in, right up against it. Add to this, walking any speed...(of course, not something ridiculous like a 5 tile walking speed... but 2 doesn't seem too bad). I've been pondering this, and I've seen some pretty good walking systems out there, but not really function well over 1 tile/0.05sec... so maybe I thought we could all put our heads together on this. EDIT: Okay, so right after I posted this I figured something out... many times I see people using for loops to detect placements between the player and the next move... I've cultivated something similar. What I did was run a for loop as: for (i=0;i<this.speed;i+=1/16) {} This will create a loop between every pixel and the speed the player is going. Then, do a wall check, incrementing the check by i: this.testx=playerx+2.5+i; This will check every pixel between the player and the next move. Now, instead of just writing a check that you're touching a wall, I did this: player.x=this.testx-2.5; This will set the player flush up against the wall, and I've done this going 5 tiles/0.05sec so far and it has worked flawlessly. I'd still love to hear more stuff about this as I'm sure everyone could benefit from it, and there must be better ways. |
I've found this works pretty well:
PHP Code:
|
Quote:
Edit: Quote:
Quote:
Quote:
|
I have it.
It's extremely complicated, and it uses angles, rather than directions. It really just depends on your usage. For something like this I'd use something like what I posted. For angular movement, definately Zero's function. |
Quote:
|
Zero's function?
That's up to him to post, not me! |
Quote:
|
Quote:
|
Quote:
|
Well, I look back and my first post was very sloppy. I wrote it in a rush and it was late, yada yada. Anyways, I think I came up with another good theory. Only theory as I've yet to test it out in a script, but here it is:
PHP Code:
EDIT: Well I have tested this method at 10tiles/0.05sec and it works perfectly... almost. Going down and right flushes you right against the wall, however up and left is a little offset. Nothing visually, but it shows in the player.x/y values as it has a semi-large floating value. I know why it's doing it, but it's an inconvenience. Either way, this method eliminates the need for pre-movement values and checks. |
1 Attachment(s)
Heh, I forgot how fun it is writing a movement system. This is what I've settled with and I'm pretty happy with it. It's not long, but the detects are a little more complicated than I had expected them to be. Ya, it's GS1, but I'll convert it to GS2 sooner or later, that's pretty easy.
:) Kick it up to 160/16(or higher, if you dare), the wall detection is flawless, and in my opinion, pretty simple. The higher you set it though, the larger the loop will get, so be careful with that. |
| All times are GMT +2. The time now is 03:48 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.