Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 03-18-2010, 04:21 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
I think I was just going about the problem wrong before, I wasn't adjusting the grid, instead I was adjusting the onwall detection, when I should be doing both.

Honestly I'm not sure, I haven't used this in awhile, but I seem to remember my edit that allowed variable size nodes not working properly.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #17  
Old 03-18-2010, 05:04 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by coreys View Post
I think I was just going about the problem wrong before, I wasn't adjusting the grid, instead I was adjusting the onwall detection, when I should be doing both.

Honestly I'm not sure, I haven't used this in awhile, but I seem to remember my edit that allowed variable size nodes not working properly.
I think my OP kind of implied that all you had to do was modify the onwall checks to find paths for larger objects (which is NOT the only thing you have to do). My bad! I'll release an updated version with variable node-size support hopefully by this weekend.

Edit: Here ya go. It seems to work, but I kind of rushed through it so let me know if you run into any problems.
findpathnew.txt

Added two more parameters.
  • nodeSize -- array, width and height of the size of the object looking for a path in tiles (for example {2,2})
  • moveByNode -- boolean, set this to false if you want to still search tile by tile (explained below). When false, your grid will be the tiles that make up a level, when true your grid will be made up of nodes of size "nodeSize"

findPath(cx, cy, tx, ty, nodeSize, moveByNode, cutCorners, fullPath)
Example of usage:
PHP Code:
findPath(player.xplayer.ytemp.targetxtemp.targety, {2,2}, falsetruefalse);
// This would search for a path from the player's location to a target location, taking into account the size of the player (2 tiles by 2 tiles) and allowing corner cutting 
Here's an image searching for a path for a 2x2-sized object on a node-basis (white is the full path, black is the important nodes, the rest is just nodes that were searched):
Click image for larger version

Name:	nodesizebig.png
Views:	125
Size:	100.5 KB
ID:	50642

It also allows you to search for nodes smaller than 1 tile, but I can't really see a reason why you'd ever want to do that:
Click image for larger version

Name:	nodesizesmall.png
Views:	128
Size:	20.2 KB
ID:	50641

Ideally, you probably want to set moveByNode to false. Otherwise you might not find a path that actually exists. Here's what I mean:
Name:  moveByNode.png
Views: 150
Size:  1.5 KB

In this picture, the gray lines represent tiles. The black lines represent what your grid will look like with moveByNode set to true. The green squares are starting and finishing nodes. The red is a wall. The pink is a spot that should be a perfectly fine spot for a 2x2 object to sit, but would not be considered fine if moveByNode is true. With moveByNode set to true, the path from one green to the other is impossible because it searches by node (black squares). When false, the path is found easily.

An example of when you might use moveByNode is for a turn-based system where NPCs can only move a certain number of nodes and/or maps are designed based on the node/object-size.

Last edited by salesman; 03-18-2010 at 07:21 PM..
Reply With Quote
  #18  
Old 03-18-2010, 07:23 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
sorry for double posting, but I forgot editing the last post doesn't bump the thread and I want coreys to know that I updated the script.
Reply With Quote
  #19  
Old 03-18-2010, 08:27 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys

Thanks. This will come in handy.
However, moving this script to serverside I've noticed it takes quite a bit of CPU usage (at least serverside, it does).

Also, you may want to add some sort of offset option, for cases like a normal player character type NPC where the top of the head doesn't need to be counted as a blocking area.

Additionally, this paper might be interesting to you! It's basically on how to efficiently find paths with variable size entities; it also has a lot on dealing with multiple types of terrain where entities have certain types of terrain they can clear but that's probably not that important (unless you want it to be!).
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.