![]() |
Function: WallIntersect
Note: This function name is terrible. I'm not good at this.
WallIntersect(x1, y1, x2, y2) What is this? Simple! I believe it was Dusty who was requesting this before: a function to check for walls on a line. This is a GS2 implemenation, obviously, so not as complex. What does it do? It takes the coordinates for two points and checks for walls on a (dotted) line between them. One regular onwall() check about every tile length and a guaranteed check on the destination coordinate (that's the second one!). It also does what has been requested of this feature and (kinda) returns where it hit a wall. It will, however, not continue to check along the line for more walls once it encounters one. How does it work? You feed it the two points and it will return an array in this format: PHP Code:
What do I do now? Well, when you have the return values, you either didn't hit a wall and everything's fine. Or you hit a wall. You can then use the returned stepsBeforeWall and angle to calculate where you can move to savely without hitting a wall. It's not that accurate, but if you need it to be, you can make some additional checks. PHP Code:
Maybe this will be of use to some of you! One more thing: this is mostly meant for players and other things with a hitbox that is 32x32 pixels. This is why I add 17 / 16 to the base of my onwall() checks. You can simply modify that if you need. |
Quote:
|
All times are GMT +2. The time now is 09:21 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.