Hello,
i am trying to set up some basics for a flash game. I was asking about help in integrating a precise collision detection from gskinners. Now i know a bit more and dont need such advanced things.
edit admits: i want the game to be Art-based, or “not Tile based”.
I´have movement, gravity, friction and jumping(yet flying). Now i want some basic collision detection for a level ,without risking to “sink into geometry”. As it is for level geometry only bounding boxes are precise enough i think. I was looking all over the net and many tutorials. I know the direction, but not the exact way. Heres what i got, and its totally wrong i think. It only works if im Falling onto a platform, and then often “sinks” into it.
Problems are the “sinking” and to check for all directions. Not being stuck in the wall in the end.
onClipEvent (load)
{
// PHYSICS
power = 5;
ymove = 0;
xmove = 0;
friction = 0.85;
gravity = 0.95
jumpForce = 5
// STATES
jumping = false;
}
onClipEvent (enterFrame)
{
if (player, hitTest(_root.ground))
{
ymove = 0 - gravity;
}
if (jumping)
{
power = 1;
ymove -= jumpForce;
jumping = false;
}
if (Key.isDown(Key.LEFT))
{
xmove -= power;
}
if (Key.isDown(Key.RIGHT))
{
xmove += power;
}
if (Key.isDown(Key.UP))
{
jumping = true;
}
xmove *= friction;
ymove += gravity;
_y += ymove;
_x += xmove;
}
I found a very small tutorial concerning movement prediction, i think this is the best way to handle it. As i want to check left, right, bottom and top. Thats how i tried to integrate it into my code.
If (player.xmove -= power;)
{
if (player, hitTest(_root.ground))
{
left = false;
}
else {left = true;}
}
if (Key.isDown(Key.LEFT) left = true)
{
xmove -= power;
}
or
if (!_root.ground.hitTest(this._x+=power,this._y,true)){right=true;}else{right=false;}
if (Key.isDown(Key.right) right = true)
{
xmove += power;
}
something like… but it wont work. Maybe someone would show and explain me a possible way.
Ill provide the code of the little tutorial, maybe you can help me adapt it to my code.
onClipEvent ( enterFrame){
if (!_root.back.hitTest(this._x+10,this._y,true)){right=true;}else{right=false;}
if (!_root.back.hitTest(this._x-10,this._y,true)){left=true;}else{left=false;}
if (!_root.back.hitTest(this._x,this._y+10,true)){down=true;}else{down=false;}
if (!_root.back.hitTest(this._x,this._y-10,true)){up=true;}else{up=false;}
if ( Key.isDown (Key.UP) and up){this._y-=10;}
if ( Key.isDown (Key.DOWN) and down){this._y+=10;}
if ( Key.isDown (Key.LEFT) and left){this._x-=10;}
if ( Key.isDown (Key.RIGHT) and right){this._x+=10;}
}
-> but here the level is only allowed to be drawed into a “10pixel square Grid” otherwise its wrong or inacurate. So i think i should replace the x+10 etc values with mine xmove -= power…
I dont expect solutions or want you doing my work or whatever, im just kindly asking if someone could help me getting on step by step.
Thanks in advance,
ask for whatever info i missed to provide
and have a nice weekend.
greets
Pygma