|
|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
Patrick
Join Date: Feb 2006
Location: Ireland
Posts: 42
|
HELP object moves left, when hits a wall, how do I make him turn around and move that
Hey guys,
I am not a compleat noob at actionscripting but I have a problem here..very tricky and flash always ends up terminating the script during gamplay as it just does not work the way I think it should. Anyway. I will give you an example of what I am doing: I am making a game like Security 2. 2D overhead view where you are an agent going from room to room collecting objects and compleating objectives. So far I have managed to create 1 unit..and duplicate that to make many more enemys which makes things very easy. Now, I have the enemy spawn randomly around the map..max units are 7 and they will auto move to the left. Code looks like this: this._x = random(600)+100; this._y = random(480); this.speed = random(3)+1; now..I want it so when they meet a wall, they will rotate 180 degrees and move the other way...and t hen onec they hit another wall..they will rotate again and move that way! this code is long here..works perfectly atm...it spawns the units..tells them to move at a random speed and spawn randomly...if you can..please show me how to make it so..hey will turn and move the other way!! onClipEvent (load) { function reset() { if (this._name == "enemy") { this._visible = false; } else { this._visible = true; } this._x = random(600)+100; this._y = random(480); this.speed = random(3)+1; } this.reset(); } onClipEvent (enterFrame) { this._x -= this.speed; if (this._x<-50) { this.reset(); } } onClipEvent (load) { power = 3; radius = 6; } onClipEvent (enterFrame) { while (_root.wall.hitTest(_x-radius, _y, true)) { _x++; } while (_root.wall.hitTest(_x+radius, _y, true)) { _x--; } if ((_root.enemy.hitTest(_x, _y+radius, true)) or (_root.enemy.hitTest(_x, _y-radius, true)) or (_root.enemy.hitTest(_x+radius, _y, true)) or (_root.enemy.hitTest(_x-radius, _y, true))) { _x = 1000; _y = 1000; } } Thank you for listening and I hope you can give me a hand.
|
|
|
|
|
|
#2 |
|
Member
Join Date: Jul 2007
Posts: 32
|
I think this will do it ( i havent tested).
if(this.hitTest(_root.wall_right) this._rotation = 180 move = 5 plusminus = + } } the moving is the variable move. you will have to do like this in the begining: this._x plusminus= move (dont know if plusminus is working) it will look like this in the end: this._x += 5 i dont know if you can write: this._x = +5 if you can you can just set move to +5 so it whould look like this: this._x = move or: this._x = +5 Hope this will help you. |
|
|
|
|
|
#3 |
|
Patrick
Join Date: Feb 2006
Location: Ireland
Posts: 42
|
Thanks! I shall try this out!
|
|
|
|
|
|
#4 |
|
Member
Join Date: Jul 2007
Posts: 32
|
You are welcome
|
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|