I would like to know how to simply use hittests to block players (using the arrow keys to move) and npc characters. I’ve seen tons of tutorials and none of them have worked when I did it.
What specifically did not work with the code you used?
[ot]That is *weirdest *way to close a post I’ve seen all week![/ot]
the entire code is ignored and the player goes right through the wall
Post your code, we’re not mind readers.
sorry,
in the player:
on(load){
playerspeed = 5
onClipEvent(enterFrame){
if(key.isDown(key.UP)){
this._y -= playerspeed
}
if(key.isDown(key.UP)){
this._y -= playerspeed
}
if(key.isDown(key.DOWN)){
this._y += playerspeed
}
if(key.isDown(key.LEFT)){
this._y -= playerspeed
}
if(key.isDown(key.RIGHT)){
this._y += playerspeed
}
if(this.hitest(wall)){
playerspeed = 0
}else{
playerspeed = 5
}
}
The method is hitTest, not hitest.
I know, I made a typo
because you’re doing it on load, doing it on enterFrame
thanx
so how would i write the code correctly in flash 8?
you need to close your on(load){
I forgot to close it after “playerspeed” ---- typo!!!
still wondering though
well if you closed the load and changed hitest to hitTest, then the only thing i can think of is to change this line
if(this.hitest(wall)){
to this lind
if(this.hitTest(_root.wall)){
you are using instance names right?
hitTest=tests if there is a collision between two diffrent movie clip.
It will take the collision of the bounding boxes of each movie clip.
The correct code for your moving character would be…
onClipEvent(load){
playerspeed = 5
}
onClipEvent(enterFrame){
if (Key.isDown(Key.LEFT)){
_x-=speed;
}
if (Key.isDown(Key.RIGHT)){
_x+=speed;
}
if(Key.isDown(Key.UP)){
_y-=speed
}
if(Key.isDown(Key.DOWN)){
_y+=speed
}
if(this.hitTest(_root.wall)){
playerspeed = 0
}else{
playerspeed = 5
}
}
or along those lines.