ForumsProgramming ForumAs2 Knockback code

5 4347
DapwnageG
offline
DapwnageG
205 posts
Nomad

I am working on a game in which the player must fight enemies and go through obstacles in an eagle's eye perspective. I need to make it so when the player attacks an enemy, it gets knocked backwards so it won't die right away. This is the code:


onClipEvent(load){
knock = false;
knockback = 30;
}
onClipEvent(enterFrame){
if(knock == true){
knockback -= 5;
if(_root.Player._rotation >= 45 && _root.Player._rotation <= 135){
this._x += knockback;
}
if(_root.Player._rotation >= 135 && _root.Player._rotation <= 225){
this._y += knockback;
}
if(_root.Player._rotation >= 225 && _root.Player._rotation <= 315){
this._x -= knockback;
}
if(_root.Player._rotation >= 315 && _root.Player._rotation <= 405){
this._y -= knockback;
}

if(knockback < 1){
knockback = 30;
knock = false;
}
}
}


Everything works except the bold statements. The enemy cannot fly left or upwards.

Could anyone tell me why that is? Thanks in advance.

  • 5 Replies
rjbman
offline
rjbman
215 posts
Nomad

I'm pretty sure that the rotation only goes to 180. Try replacing it with negatives instead (360- whatever you need, but then add negative).

DapwnageG
offline
DapwnageG
205 posts
Nomad

I don't understand what you are saying. You want to change it to this?

if(_root.Player._rotation >= -225 && _root.Player._rotation <= -315){
this._x -= knockback;
}


or like this?

if(_root.Player._rotation >= -45 && _root.Player._rotation <= -135){
this._x -= knockback;
}

alsage
offline
alsage
132 posts
Nomad

yeah thats what he means... Flash uses 180 degree lines... so anything above the line would be like +65 anything below would be -65

DapwnageG
offline
DapwnageG
205 posts
Nomad

Ok thanks! It worked! The battling system works really well and looks amazing.

rjbman
offline
rjbman
215 posts
Nomad

Great! Hope the game does well.

Showing 1-5 of 5