im trying to make a game where your character is moving around the screen…and i want to make it so the character stops in certain areas…like a cliff, i dont want the character to be able to walk over the cliff…i have been searching for actionscripts and whatnot…and i just cant find it…please help…
flash MX
one method would be to test the position of your character and see if it is over a certain point, for example, say i wanted to make sure that my character wouldn’t go to a point where it’s _x value is less than 100 and it’s _x is greater than 200, i could do something like this:
onClipEvent(enterFrame) {
if (this._x < 100) {
this._x = 100;
} else if (this._x > 200) {
this._x = 200;
}
}
thats almost exactly what i am looking for…but can i make that same effect happen when my player goes ontop of another movie clip?ill post some screen shots
this is what the scene looks like…
this is the character:
this is the ditch that i dont want the character to be able to go over top of:
this is the actionscript i have for the character so you can move him with the arrow keys:
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN)) {
this._y = this._y+10;
gotoAndStop(2);
}
if (Key.isDown(Key.UP)) {
this._y = this._y-10;
gotoAndStop(4);
}
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+10;
gotoAndStop(3);
}
if (Key.isDown(Key.LEFT)) {
this._x = this._x-10;
gotoAndStop(5);
}
}
onClipEvent (keyUp) {
gotoAndStop(1);
}
onClipEvent (enterFrame) {
if (_root.player, hitTest(_root.holeblock1)) {
gotoAndStop(1);
}
}
is there an AS that i can use to keep the character from going overtop of the ditch??
do they have to be on the same layer?
what about using hitTest()?
i dont understand how to make the character stop moving with a hit test
you just test to see if the character’s bounding box is intersecting another object’s bounding box.
huh :h:
how the heck do i do that???..
sorry…im just not very good at this stuff :puzzle:
if (mcCharacter.hitTest(mcDitch)) {
//put code to stop the Character now
trace(“you hit the Ditch and You Cannot move further”);
}
what is the code to stop the character??
i dont want it to say anything…i just want it to stop moving
onClipEvent (enterFrame) {
if (canMove) {
if (Key.isDown(Key.DOWN)) {
prevY = _y
this._y = this._y+10;
gotoAndStop(2);
}
if (Key.isDown(Key.UP)) {
prevY = _y
this._y = this._y-10;
gotoAndStop(4);
}
if (Key.isDown(Key.RIGHT)) {
prevX = _x
this._x = this._x+10;
gotoAndStop(3);
}
if (Key.isDown(Key.LEFT)) {
prevX = _x
this._x = this._x-10;
gotoAndStop(5);
}
}
}
onClipEvent (keyUp) {
gotoAndStop(1);
}
onClipEvent (enterFrame) {
if (_root.player, hitTest(_root.holeblock1)) {
_x = prevX;
_y = prevY;
gotoAndStop(1);
}
}
possibly a better option here would be to go for the coordinates of the feet, this way his head can go over the cliff, but his feet cannnot - giving the effect that he can walk right upto it.
the way you would do this is:
onClipEvent (enterFrame) {
if (_root.player, hitTest(_root.player._x, _root.player_y, true) {
_x = prevX;
_y = prevY;
gotoAndStop(1);
}
}
hope this helps
now my guy wont even move.
i attached a fla of an example of what i want…
MX2004
if earlier version is needed…just ask…i can add it as MX
mx would be useful for me.
ok…here is the MX version…
after a long day off frantic searching of how to stop a characters movement…i finally came up with a solution.
here is the code that made the character move:
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN)) {
this._y = this._y+10;
gotoAndStop(2);
}
if (Key.isDown(Key.UP)) {
this._y = this._y-10;
gotoAndStop(3);
}
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+10;
gotoAndStop(4);
}
if (Key.isDown(Key.LEFT)) {
this._x = this._x-10;
gotoAndStop(5);
}
}
and here is what i came up with to stop the chracter from moving:
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN)) {
this._y = this._y+10;
gotoAndStop(2);
}
if (Key.isDown(Key.UP)) {
this._y = this._y-10;
gotoAndStop(3);
}
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+10;
gotoAndStop(4);
}
if (Key.isDown(Key.LEFT)) {
this._x = this._x-10;
gotoAndStop(5);
}
if (this.hitTest(_root.stopright)){
this._x = this._x-10;
gotoAndStop(4);
}
if (this.hitTest(_root.stopleft)){
this._x = this._x-10;
gotoAndStop(5);
}
if (this.hitTest(_root.stopup)){
this._y = this._y-10;
gotoAndStop(3);
}
if (this.hitTest(_root.stopdown)){
this._y = this._y+10;
gotoAndStop(2);
}
}
finally…now…if anyone knows a better way…please let me know
i want a MC that has an odd shape to it…everytime i try to get the character to stop on a MC it works, but its always a straight line…i want a more organic shape … i know that it is possible…i have seen it done before…but i cant get anyone to hel me out with it…
PLEASE help me…