Forum Topic: AS gravity problem

(338 views • 5 replies)

This topic is 1 page long.

<< < > >>
None

D-SuN

Reply To Post Reply & Quote

Posted at: 3/6/06 11:02 AM

D-SuN NEUTRAL LEVEL 14

Sign-Up: 01/04/04

Posts: 128

hello there,
I wrote a gravity script that i'm very happy with. the only problem is that if the object falls from a cretant hight, he wall fall through the ground or get stuck in the middle. this is an issue because in the game im making, i realy can have him sticking through the ground. If someone could help me to understand this, explain why it is happerning (please) and how to fix it, much would be appreciated.
this is the script. it wroks well, expet for high hights
onClipEvent (load) {
fallSpeed = .2;
maxFallSpeed =10;
grav_y = 0;
fall = true;
}
//gravity
onClipEvent (enterFrame) {
if (grav_y>MaxFallSpeed) {
grav_y -=1;
}
if (fall == false) {
grav_y = 0;
}
if (fall == true) {
grav_y += fallSpeed;
if (grav_y>0) {
grav_y += fallSpeed;
}
}
if (_root.ground.hitTest(_x, _y, true) == false) {
fall = true;
}
if (_root.ground.hitTest(_x, _y, true)) {
fall = false;
}
this._y += grav_y;
}
onClipEvent (enterFrame) {
if (_root.ground.hitTest(_x, _y, true)) {
this._y -=grav_y;
grav_y = 0;
}
}


None

Shinki

Reply To Post Reply & Quote

Posted at: 3/6/06 11:29 AM

Shinki DARK LEVEL 10

Sign-Up: 02/14/05

Posts: 1,381

Yea your problem is you are changing the y position by the value of gravity, so when it is moving several points each time your hittest will miss it. I had this problem, I got round it by using a for loop that moves the object 1 point, gravity no. of times, and does a hittest at each.
eg:
for(i=gravityAbs; i>0; i--){ // create an absolute variable beforehand if you sometimes have negative values of gravity.
groundCheck = (check whether your object would hit the ground if moved 1 point)
if (groundCheck){
i=1}
else{
(change y pos by 1 in correct direction)
}
}

If a picture is worth a thousand words, a game is worth a play. New game! In AS 3.0. :D

BBS Signature

None

D-SuN

Reply To Post Reply & Quote

Posted at: 3/6/06 02:20 PM

D-SuN NEUTRAL LEVEL 14

Sign-Up: 01/04/04

Posts: 128

At 3/6/06 11:29 AM, ShinKi wrote: Yea your problem is you are changing the y position by the value of gravity, so when it is moving several points each time your hittest will miss it. I had this problem, I got round it by using a for loop that moves the object 1 point, gravity no. of times, and does a hittest at each.

woo man. thats awome its working. i dont understand the script at all. i pasted it in and tryed to figure it out. am i able to use it as walls on the x axis?


None

nokotin

Reply To Post Reply & Quote

Posted at: 3/6/06 02:24 PM

nokotin NEUTRAL LEVEL 11

Sign-Up: 06/27/05

Posts: 162


woo man. thats awome its working. i dont understand the script at all. i pasted it in and tryed to figure it out. am i able to use it as walls on the x axis?

how can you not understand a script you wrote?


None

D-SuN

Reply To Post Reply & Quote

Posted at: 3/6/06 11:45 PM

D-SuN NEUTRAL LEVEL 14

Sign-Up: 01/04/04

Posts: 128

At 3/6/06 02:24 PM, nokotin wrote:

woo man. thats awome its working. i dont understand the script at all. i pasted it in and tryed to figure it out. am i able to use it as walls on the x axis?
how can you not understand a script you wrote?

Who says i was talking about my spript?


None

Shinki

Reply To Post Reply & Quote

Posted at: 3/7/06 12:51 PM

Shinki DARK LEVEL 10

Sign-Up: 02/14/05

Posts: 1,381

yea, use it for x movement too =)

If a picture is worth a thousand words, a game is worth a play. New game! In AS 3.0. :D

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 12:58 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!