hitTest troubles...

6 posts

Flag Post

Im having trouble with my sprite to realize its running into an object… ive went through all the debugging steps I could think of… so I think I’ll ask you. Could you all proof-read this? help me find where Im wrong at? I run Flash MX Pro 2004 on Mac 10.3.9- i have this typed on sprite instance shooter, and its interacting with the keys, the mouse, and bottom_w (wall) I wish..

onClipEvent (load) {
power = 0.5;
yspeed = 0;
xspeed = 0;
friction = 0.95;
thrust = 0.75;
gravity = 0.05;
}

onClipEvent (enterFrame) {
if (Key.isDown (Key.LEFT)) {
if (!root.bottom_w.hitTest (x -= 5, _y, true)) {
x -= 5;
}
}
if (Key.isDown (Key.RIGHT)) {
if (!root.bottomw.hitTest(
x = 5, _y, true)) {
x += 5;
}
}
if (Key.isDown (Key.UP)) {
if (!root.bottomw.hitTest(
x, _y -= 5
thrust, true)) {
y -= 5+thrust;
}
}
if (Key.isDown (Key.DOWN)) {
if (!root.bottomw.hitTest(
x, _y = 5thrust, true)) {
_y = 5thrust;
}
}
xspeed *= friction;
yspeed += gravity;
_y += yspeed;
x += xspeed;
if ((root.bottomw.hitTest(
x, _y, true)) and ((angle>90) and (angle<270))){
xspeed = 0;
yspeed = 0;
_x = 120;
y = 120;
}
}
onClipEvent (enterFrame) {
myRadians = Math.atan2(root.ymouse-this.
y, root._xmouse-this.x);

myDegrees = Math.round((myRadians*180/Math.PI)); root.yChange = Math.round(root.ymouse-this.y); root.xChange = Math.round(root.xmouse-this.x); this._rotation = myDegrees+90;

}

sorry if that is alot of text… I have no prior coding know how, so I have no idea what went wrong here… thanks for the help,

-Jakob
 
Flag Post

Im sorry to double-post… but I’ll share my game idea, if no one cares… Im working on a little jumpy wheel, which you control with the arrows, and a turret controlled by the mouse, and a jump thatll let you float slightly (gravity would be pretty light..)… and have the combat overhead and under, and set certain physics so when they hitTest, theyll only go so far, which leaves different weapon tactics open… I would want it to be quick and jumpy controls, so that the action gets intense, maybe an explosion effect on the enemys, like in luminara. if you have any tips or comments feel free to share them!

 
Flag Post

I’m not sure if this is the cause of the problem, but where you have:

if (!_root.bottom_w.hitTest (_x -= 5, _y, true)) {

it shouldn’t be

x -= 5
it should just be
x – 5

Same for all the other hitTests with similar stuff in them.

 
Flag Post

@editundo:

That kind of thing does work in some languages, such as using while(x = y) to set x AND check if it is true, but may not work in Flash.

@Jakob:

It may be because if your if(hitTest) parts, you don’t close the curly brackets, but that may be allowed in Flash (I haven’t got Flash on this PC to check it). You might want to try (as a general practice, too) using both opening and closing brackets instead of just using one.

 
Flag Post
    if ((_root.bottom_w.hitTest(_x, _y, true)) and ((angle>90) and (angle<270))){

The ActionScript AND operator is &&. That should be

    if ((_root.bottom_w.hitTest(_x, _y, true)) && ((angle>90) && (angle<270))){
 
Flag Post

well, I fixed one part of my problem… I changed if
[pre] if (Key.isDown (Key. LEFT)) { [/pre] to
[pre] if (Key.isDown (Key. LEFT) && root.bottomw == true) { [/pre]
I now have a part 2, its the interaction with gravity and the hitTest function… with gravity on it reverses the hitTest… I have a sllight idea on what to put, mainly the _x -= such and such, but IM not sure where to put it… any ideas?