Page 1 of 1

Cant Walk on walls code??

Posted: 17 Oct 2010, 10:01
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!

Posted: 17 Oct 2010, 16:27
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.

Posted: 18 Oct 2010, 03:22
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

Posted: 26 Oct 2010, 01:48
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.

Posted: 26 Oct 2010, 02:53
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!

Posted: 26 Oct 2010, 04:53
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

Posted: 26 Oct 2010, 07:06
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.

Posted: 26 Oct 2010, 20:47
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!