Cant Walk on walls code??

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
EpicEpic
Posts: 1
Joined: 16 Oct 2010, 14:57

Cant Walk on walls code??

Post by EpicEpic »

hey guys! So i have a walk code (mouse) for a movieclip.

Like when u click somewhere the avatar goes there.
But i wanna make it so that the avatar cannot walk on buildings or the sky...

I know this is really off topic or hasn't got anything to do with sfs But i really need help :( I searched it on google nothing helped....

pls help!
ext0sus
Posts: 71
Joined: 17 Oct 2010, 16:14

Post by ext0sus »

This isn't a very secure method. Ideally you would want to check if the destination is walkable from the server side but if you're not bothered about people "hacking" your game to move where they want, you can use hitTestPoint to stop the client from ever requesting to move their avatar:

Inside your mouse click handler:

Code: Select all

if( !UNWALKABLE.hitTestPoint(e.stageX, e.stageY) ){
     //Tell smartfoxserver to move the avatar
}
Where 'UNWALKABLE' is the instance name of the movieClip containing anything you don't want the player to walk on.


This post assumes you're using AS3 and an art-based map/level.
Tree Line 1
Posts: 100
Joined: 10 Oct 2010, 02:58
Location: Australia

Post by Tree Line 1 »

ext0sus wrote:This isn't a very secure method. Ideally you would want to check if the destination is walkable from the server side but if you're not bothered about people "hacking" your game to move where they want, you can use hitTestPoint to stop the client from ever requesting to move their avatar:

Inside your mouse click handler:

Code: Select all

if( !UNWALKABLE.hitTestPoint(e.stageX, e.stageY) ){
     //Tell smartfoxserver to move the avatar
}
Where 'UNWALKABLE' is the instance name of the movieClip containing anything you don't want the player to walk on.


This post assumes you're using AS3 and an art-based map/level.
Didn't work for me
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC

Post by Carl Lydon »

You can also make a map editor so you can paint arrays that show walkable areas in form of 1 and 0, and then refer to that array.
skybucks100
Posts: 81
Joined: 15 Aug 2010, 23:16
Contact:

Post by skybucks100 »

ext0sus wrote:This isn't a very secure method. Ideally you would want to check if the destination is walkable from the server side but if you're not bothered about people "hacking" your game to move where they want, you can use hitTestPoint to stop the client from ever requesting to move their avatar:

Inside your mouse click handler:

Code: Select all

if( !UNWALKABLE.hitTestPoint(e.stageX, e.stageY) ){
     //Tell smartfoxserver to move the avatar
}
Where 'UNWALKABLE' is the instance name of the movieClip containing anything you don't want the player to walk on.


This post assumes you're using AS3 and an art-based map/level.
Hey, I was wondering can this code with in AS2? If not is there a HitTest code like this for AS2? also where it says e.stage do I put the dimensions of where i don't want the avatar to walk?

Thanks!
Best Regards,
Skybucks100
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC

Post by Carl Lydon »

Another reason it's better to make a map editor for collision testing is because then you set yourself up to do A** pathfinding.

http://carllydon.com/dropbox/roomeditor/RoomEditor.swf
ext0sus
Posts: 71
Joined: 17 Oct 2010, 16:14

Post by ext0sus »

skybucks100 wrote:
ext0sus wrote:This isn't a very secure method. Ideally you would want to check if the destination is walkable from the server side but if you're not bothered about people "hacking" your game to move where they want, you can use hitTestPoint to stop the client from ever requesting to move their avatar:

Inside your mouse click handler:

Code: Select all

if( !UNWALKABLE.hitTestPoint(e.stageX, e.stageY) ){
     //Tell smartfoxserver to move the avatar
}
Where 'UNWALKABLE' is the instance name of the movieClip containing anything you don't want the player to walk on.


This post assumes you're using AS3 and an art-based map/level.
Hey, I was wondering can this code with in AS2? If not is there a HitTest code like this for AS2? also where it says e.stage do I put the dimensions of where i don't want the avatar to walk?

Thanks!
There is a hitTest function for AS2. Just Google "AS2 hitTest" and you'll find a lot of information about it.

But Carl Lydon is right, it's much better to use a tile-based system. Having your map arranged into tiles has a lot of advantages including being easier to program AI and check collisions on the server side.

There are lots of other advantages but it would take me a while to list them.
skybucks100
Posts: 81
Joined: 15 Aug 2010, 23:16
Contact:

Post by skybucks100 »

ext0sus wrote:
skybucks100 wrote:
ext0sus wrote:This isn't a very secure method. Ideally you would want to check if the destination is walkable from the server side but if you're not bothered about people "hacking" your game to move where they want, you can use hitTestPoint to stop the client from ever requesting to move their avatar:

Inside your mouse click handler:

Code: Select all

if( !UNWALKABLE.hitTestPoint(e.stageX, e.stageY) ){
     //Tell smartfoxserver to move the avatar
}
Where 'UNWALKABLE' is the instance name of the movieClip containing anything you don't want the player to walk on.


This post assumes you're using AS3 and an art-based map/level.
Hey, I was wondering can this code with in AS2? If not is there a HitTest code like this for AS2? also where it says e.stage do I put the dimensions of where i don't want the avatar to walk?

Thanks!
There is a hitTest function for AS2. Just Google "AS2 hitTest" and you'll find a lot of information about it.

But Carl Lydon is right, it's much better to use a tile-based system. Having your map arranged into tiles has a lot of advantages including being easier to program AI and check collisions on the server side.

There are lots of other advantages but it would take me a while to list them.
Yep I googled it and the first link was a Adobe Flash one from Adobe if anyone else was looking for the code this is what i found:

myMovieClip .hitTest( x, y, shapeFlag )
myMovieClip .hitTest( target )

Gonna try it and see if it works!
Best Regards,
Skybucks100
Post Reply