ForumsProgramming Forumplatform game help

16 8389
rino
offline
rino
27 posts
Nomad

I am making a platform game in AS2 for school and everything works, but the rotation of the character to the ground. The problem is, is that the character hits the symbol box and not the image inside it.So does anyone know how to make it hit the image and not the symbol box around it

Here is the code:

onClipEvent (load) {
speed = 4;
jump = 0;
jumpheight = 9;
gravity = 0.5;
scale = _xscale;
wid = _width/2;
heig = _height/2;

}
onClipEvent (enterFrame) {
_y -= jump;
jump -= gravity;
if (Key.isDown(Key.LEFT)) {
_x -= speed;
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
_xscale = +scale;
}
while (_root.ground.hitTest(_x, _y+heig, true)) {
_y--;
jump = -5;
inair = false;
if (inair == false && Key.isDown(Key.UP)) {
jump = jumpheight;
inair = true;
}
}
while (_root.ground.hitTest(_x, _y-heig, true)) {
jump = -jump;
_y++;
}
while (_root.ground.hitTest(_x+wid, _y, true)) {
_x--;
}
while (_root.ground.hitTest(_x-wid, _y, true)) {
_x++;
}
}
onClipEvent (enterframe) {
if (_root.ground.hitTest(_root.player[&quotoint"])){
_root.player._rotation -= 1;
trace("hit"
}else{
_root.player._rotation +=1;
trace("not"
}
}

  • 16 Replies
Diddy645
offline
Diddy645
23 posts
Nomad

why do you say _xscale = -scale? You also defined the variable scale to equal _xscale...so you are never telling it to = 1 or -1. You are just telling it to equal itself, which is probably why it won't work. What you should do is just replace the line _xscale = -scale; in the left key down statement with _xscale = -1; and the _xscale = +scale; in the right key down statement with _xscale = 1;

rino
offline
rino
27 posts
Nomad

I just tried it and it made the character become a line

Diddy645
offline
Diddy645
23 posts
Nomad

Ok, I was thinking about what I had said, since I use AS3, not AS2. I always forget if _xscale is on a scale of 1 to -1 or 100 to -100. Try _xscale = 100;, etc, in place of _xscale = 1;

rino
offline
rino
27 posts
Nomad

it's still only hiting the symbol box and not the real image.

Diddy645
offline
Diddy645
23 posts
Nomad

It might have something to do with your many unnecessary while statements.

rino
offline
rino
27 posts
Nomad

ya i remove them

rino
offline
rino
27 posts
Nomad

ok, here is the new code.
It now has two dots that are seeing if it hits a slope

Code:
onClipEvent (load) {
speed = 4;
jump = 0;
jumpheight = 9;
gravity = 0.5;
scale = _xscale;
wid = _width/2;
heig = _height/2;
//when the character moves his feet will play the animation, but when the movement stops, the feet reset to a rest position
}

onClipEvent (enterFrame) {
_y -= jump;
jump -= gravity;
if (Key.isDown(65)) {
_x -= speed;
_xscale = -scale;
}
if (Key.isDown(68)) {
_x += speed;
_xscale = +scale;
}

while (_root.ground.hitTest(_x, _y+heig, true)) {
_y--;
jump = -5;
inair = false;
if (inair == false && Key.isDown(87)) {
jump = jumpheight;
inair = true;
}
}
}

onClipEvent (enterframe) {
if (_root.ground.hitTest(_root.player["rightpoint"])){
if (_root.ground.hitTest(_root.player["leftpoint"])){
_root.player._rotation =0;
}else{
if (_root.ground.hitTest(_root.player["rightpoint"])){
_root.player._rotation -=1;
}else{
if (_root.ground.hitTest(_root.player["leftpoint"])){
_root.player._rotation +=1;
}
}
}

}
}

rino
offline
rino
27 posts
Nomad

anyone have any idea how to make it rotate

Recklusfire1
offline
Recklusfire1
20 posts
Nomad

I see what your problem is and I understand how it can be frustrating. There are a few things you can do to fix it.

1. Probably the easiest way to fix this is to create a smaller, "hidden" box around the character to create a more accurate effect.

2. Find a "Pixel Perfect Collision Detector." There are people out there that wrote their own class to create a feature that isn't native to flash. It will probably seem complex, but you will get used to it after awhile.

dank
offline
dank
983 posts
Peasant

It depends on what you're colliding. If you're trying to test a ball against a polygon, you can loop through a number of points around the circle and see if any of them are colliding using the shapeFlag = true param. Or you can use a bit more complicated approach and test every pixel, or you can do something in between, though it's much more complex, but it is from the developers of n and is a great tutorial.

rino
offline
rino
27 posts
Nomad

Are there any easyier ways

dank
offline
dank
983 posts
Peasant

Are there any easyier ways

no
PixelSmash
offline
PixelSmash
566 posts
Nomad

That would probably be a great improvement for Flash... having a hittest that you can use as easily as objectA.hitTest(objectB) but which does allow the freedom of choosing wether to use bounding boxes, or the actual shapes.

Right now, like dank said, there are no easier ways.

skellortor
offline
skellortor
81 posts
Nomad

..... uhhh....

rino
offline
rino
27 posts
Nomad

found an easyier way to have a character rotate on a curve, will post later

Showing 1-15 of 16