-
Amiga freak
Check if a guy is to the left or right of you....??
I have a tiny little problem.....
Code:
onClipEvent (enterFrame) {
if (_root.guy.highkick.highkick.hitTest(_parent)) {
Hita = new Sound();
Hita.attachSound("Hita");
Hita.start();
_root.boss -= 1;
_parent._x -= 5;
}
}
The above code is located on a MC in my boss MC. "guy" is the player. So.... if guy hits the boss, a hit sound is played, 1 HP is drawn from the boss' health and the boss is moved 5 pixels back if boss is facing right which means that "guy" is to the right......
My problem is, how can the boss tell if the "guy" is to the left or right of him?
if "guy" is to the left, then "_parent._x += 5;", else if "guy" is to the right, then "_parent._x -= 5;"
thanks.
-
Who needs pants?
Wouldnt you just compare the _x values if its greater its to the right if its less then its to the left.
Its just a thought
-
Amiga freak
Yepp, that's the way to do it.... I just couldn't get the correct coding.
-
Who needs pants?
Code:
onClipEvent(enterFrame){
if(_root.boss._x >= _x){
//i am right
}
if(_root.boss._x <= _x){
//i am left
}
}
Thats about it
-
Who needs pants?
Just noticed something
change
Code:
onClipEvent(enterFrame){
if(_root.boss._x >= _x){
//i am right
}
if(_root.boss._x <= _x){
//i am left
}
}
too
Code:
onClipEvent(enterFrame){
if(_root.boss._x >= _x+1){
//i am right
}
if(_root.boss._x <= _x-1){
//i am left
}
}
-
Yes we can
hey there ironclaw,check your game´s fla,i already added such a script into the movement code of the normal enemies.
(if the player is right of enemies,they move right..)
-
Who needs pants?
Yeah just ignore everything i tell ya eh, listen to lord tomsamson
It would probally be the smartest thing to do
-
Amiga freak
Yepp, tomsamson, That was the first thing I looked at when I came up with the idea..... couldn't work it out though..
In the code I got from you Hooligan, you had "root.boss._x", _root.boss is the boss' health .
Tried something like this, but where ever I stand, left or right, the boss moves 5 pixels to the right..
Code:
onClipEvent (enterFrame) {
if (_root.guy.highkick.highkick.hitTest(_parent) and _root.guy._x>=_x+1) {
Hita = new Sound();
Hita.attachSound("Hita");
Hita.start();
_root.boss -= 1;
_parent._x += 5;
}
if (_root.guy.highkick.highkick.hitTest(_parent) and _root.guy._x<=_x-1) {
Hita = new Sound();
Hita.attachSound("Hita");
Hita.start();
_root.boss -= 1;
_parent._x -= 5;
}
}
Last edited by Ironclaw; 05-24-2003 at 10:46 AM.
-
Amiga freak
Only need this.... with a left and right check.
Code:
onClipEvent (enterFrame) {
if (_root.guy.highkick.highkick.hitTest(_parent) and _root.guy._x>=_x) {
_parent._x += 5;
}
if (_root.guy.highkick.highkick.hitTest(_parent) and _root.guy._x<=_x) {
_parent._x -= 5;
}
}
Also tried "_root.guy._x<=_parent" as the code is on a MC.
wont work.
-
Amiga freak
Arghh!! I give up... tried:
Code:
_root.guy._x>=_parent._x
Code:
_root.guy._x>_parent._x
Code:
_root.guy._x>=this._x
Code:
_root.guy._x>this._x
Also tried all the above but with +1 and +5 after the _x.
and "}else if" instead of "if"
Code:
onClipEvent (enterFrame) {
if (_root.guy.highkick.highkick.hitTest(_parent) and _root.guy._x>=_x) {
_parent._x += 5;
}
}else if (_root.guy.highkick.highkick.hitTest(_parent) and _root.guy._x<=_x) {
_parent._x -= 5;
}
}
-
Amiga freak
Also tried all combinations with this:
Code:
onClipEvent (enterFrame) {
if (_root.guy.highkick.highkick.hitTest(_parent) and _parent._x>=_root.guy._x) {
_parent._x += 5;
}
if (_root.guy.highkick.highkick.hitTest(_parent) and _parent._x<=_root.guy._x) {
_parent._x -= 5;
}
}
using tomsamson's
walking script:
Code:
function move(){
walk1=1.5;
walk2=1.5;
point = new object();
point.x = _root.Guy._x
point.y = _root.Guy._y;
_root.bg.globalToLocal(point);
if(_x<point.x){
_xscale=100;
this._x += walk1;
}
if(_x>point.x){
_xscale=-100;
this._x -= walk2;
}
}
move();
This script uses "if enemy is < of guy"
The others in this post uses "if guy is < of enemy"
So no wonder it doesn't work, it's just reversed.... anyway..... all of the scripts I've posted should work...except the first one.... can't understand why they don't
-
Senior Member
Originally posted by Ironclaw
Also tried all combinations with this:
Code:
onClipEvent (enterFrame) {
if (_root.guy.highkick.highkick.hitTest(_parent) and _parent._x>=_root.guy._x) {
_parent._x += 5;
}
if (_root.guy.highkick.highkick.hitTest(_parent) and _parent._x<=_root.guy._x) {
_parent._x -= 5;
}
}
It has to work as long you actually move _root.guy so its _x changes.
If you cant get it work, use trace
Code:
onClipEvent (enterFrame) {
if (_root.guy.highkick.highkick.hitTest(_parent) and _parent._x>=_root.guy._x) {
trace(_parent._x);
trace(_root.guy._x);
_parent._x += 5;
}
if (_root.guy.highkick.highkick.hitTest(_parent) and _parent._x<=_root.guy._x) {
trace(_parent._x);
trace(_root.guy._x);
_parent._x -= 5;
}
}
-
Amiga freak
Tried trace before.... Only the first "if" is executed... so the enemy is moved +5 pixels... not the other one...
I will make a example fla for you all to look at and maybe try to fix.
Later.... going out now.
-
ism
if the boss mc is facing upwards or downwards within it's mc then try this;
Code:
onClipEvent (enterFrame) {
var p = { x: 0, y: 0 };
_root.guy.localToGlobal(p);
globalToLocal(p);
if (p.x > 0)
// Guy is on the right
else
// Guy is on left or directly in front
}
Graphics Attract, Motion Engages, Gameplay Addicts
XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro
-
Amiga freak
Localtoglobal should not be neccesary, I think...... all the enemy needs to do is to see if the guy is to the left or right.... I tried your code but there's no change....
Brobably used it wrong...
Code:
onClipEvent (enterFrame) {
var p = {x:0, y:0};
_root.guy.localToGlobal(p);
globalToLocal(p);
if (p.x>0) {
if (_root.guy.highkick.highkick.hitTest(_parent)) {
_parent._x -= 5;
} else if (_root.guy.highkick.highkick.hitTest(_parent)) {
_parent._x += 5;
}
}
}
Anyway. I have made a little example fla. The boss' code is located inside MC on the left side of the stage and on keyframe 4 above his head.
-
Senior Member
Works for me
Only made it for highkick, but boss DOES move back.
-
Amiga freak
Damn.. it work in the example fla but not when applying it to the game... Maybe I DO need to use the localtoglobal thing...
here is a new fla using the attachment... (ehh, the attach method in Flash that is)
press the green button to attach the boss.
Last edited by Ironclaw; 05-25-2003 at 05:58 AM.
-
Senior Member
Yeah, you have boss inside bg mc and bc is moved, so you could use local to global.
Or you could use simple way for people who dont use localtoglobal magic (like me) and add bg mc x coordinate to if statement.
Code:
if (_parent._x+_parent._parent._x<_root.guy._x) {
_parent._x -= 5;
} else {
_parent._x += 5;
}
Hope this helped
-
Amiga freak
-
Amiga freak
I could solve it in a uneccesary complicated way involving two new MCs and a few variables..
Maybe someone know of a... more cleverly way?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|