## Flying/Float

• 420 Views
• 5 Replies
Rule
Rule
• Member since: Jan. 21, 2005
• Offline.
Forum Stats
Member
Level 43
Blank Slate
Flying/Float 2009-11-30 21:49:12

I'm working on a platform game. The character could jump and move, which is good, I just want the character to fly or float. Uh, I'm continuing this from years ago, so it's in AS 2.0. I have a flying variable which is linked to a flight bar. When the bar goes down, the flying stops and the character goes back to the floor. Does anyone know how to go about doing this?

...

ProfessorFlash
ProfessorFlash
• Member since: Oct. 6, 2007
• Offline.
Forum Stats
Member
Level 32
Programmer
Response to Flying/Float 2009-11-30 22:17:25

I assume when jumping you are adding gravity to the players _y movement. With flying you just do the opposite. When you want to float, you 'disable' gravity. That's the principle in a nutshell. If you run into problems with coding that then post the code.

You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.

digitalk
digitalk
• Member since: Dec. 16, 2006
• Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to Flying/Float 2009-11-30 22:22:47

At 11/30/09 10:17 PM, ProfessorFlash wrote: I assume when jumping you are adding gravity to the players _y movement. With flying you just do the opposite. When you want to float, you 'disable' gravity. That's the principle in a nutshell. If you run into problems with coding that then post the code.

heres my take on it

have a variable fly/float

when its active (Thats if float bar is more then 1!) the variable float/fly becomes active. and this will make players Yspeed become 0.5, taht way he isnt flying in the same place but slowly floating down

eg

if (Key.isDown(Key.SPACE) && FloatTime>0) {Float=true}
if (Float==true && FloatTime>0) {Yspeed=0.5} //Replace Yspeed with your speed variable
if (FloatTime<1) {Float=false}

enjoy.

PM me or Msn me for questions or help with flash 8! E-mail: Digital_kieren@hotmail.com, or just PM digitalk on newgrounds.

Rule
Rule
• Member since: Jan. 21, 2005
• Offline.
Forum Stats
Member
Level 43
Blank Slate
Response to Flying/Float 2009-11-30 22:33:11

Here's the jump code I have. I'm thinking the last piece of codes have something to do with it.

if (Key.isDown(Key.UP) && !jumping) {
jumping = true;
}
if (jumping) {
this.gotoAndStop("float");
this._y -= jump;
jump -= .5;
if (jump<0) {
falling = true;
}
if (jump<-15) {
jump = -15;
}
}
if (_root.ground_mc.floors_mc.hitTest(this.
_x, this._y, true) && falling) {
jump = 12;
jumping = false;
falling = false;
}
if (!_root.ground_mc.floors_mc.hitTest(this ._x, this._y, true) && !jumping) {
this._y += 6;
}

...

Rule
Rule
• Member since: Jan. 21, 2005
• Offline.
Forum Stats
Member
Level 43
Blank Slate
Response to Flying/Float 2009-11-30 22:45:31

At 11/30/09 10:22 PM, digitalk wrote:
At 11/30/09 10:17 PM, ProfessorFlash wrote: I assume when jumping you are adding gravity to the players _y movement. With flying you just do the opposite. When you want to float, you 'disable' gravity. That's the principle in a nutshell. If you run into problems with coding that then post the code.
heres my take on it

have a variable fly/float

when its active (Thats if float bar is more then 1!) the variable float/fly becomes active. and this will make players Yspeed become 0.5, taht way he isnt flying in the same place but slowly floating down

eg

if (Key.isDown(Key.SPACE) && FloatTime>0) {Float=true}
if (Float==true && FloatTime>0) {Yspeed=0.5} //Replace Yspeed with your speed variable
if (FloatTime<1) {Float=false}

enjoy.

The Float Time would represent the float bar right?
If you would continue to hold the space button, wouldn't float time pass 1? Sorry, I'm not a good coder.

...

digitalk
digitalk
• Member since: Dec. 16, 2006
• Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to Flying/Float 2009-11-30 23:59:31

thats a rather godawful code that jump one.

i realy dont like it when people have a jump up, then a falling variable, its sooo unecisary, let me re-write that for you.

grav is how harsh the gravity is

if (Key.isDown(Key.UP) && jumping==false) {Yspeed=-25; jumping=true}
if (Key.isDown(Key.UP) && FloatTime>0) {Float=true}
if (Float==true && FloatTime>0) {Yspeed=0.5; FloatTime--} //Replace Yspeed with your speed variable
if (FloatTime<1) {Float=false}
Yspeed+=grav
_y+=Yspeed
for (Yspeed+=grav; _root.ground.hitTest(_x, _y, true); Yspeed = 0) {_y-=grav}
if (_root.ground.hitTest(_x, _y+_height+10, true)) {jumping = false}

hope this works, if it doesnt sorry to dissapoint

PM me or Msn me for questions or help with flash 8! E-mail: Digital_kieren@hotmail.com, or just PM digitalk on newgrounds.