Be a Supporter!

grav code

  • 448 Views
  • 24 Replies
New Topic Respond to this Topic
micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
grav code 2009-01-22 08:46:00 Reply

onClipEvent (load) {
grav = 0;
}
onClipEvent (load) {
this._y += grav;
grav++;
}
idk whats wrong? The mc should have gravity but doesnt


...

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to grav code 2009-01-22 10:29:05 Reply

Nope, won't do anything because you need the second bit of code inside an enter frame event.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
Havegum
Havegum
  • Member since: Oct. 20, 2008
  • Offline.
Forum Stats
Supporter
Level 24
Melancholy
Response to grav code 2009-01-22 10:57:26 Reply

At 1/22/09 08:46 AM, micky315 wrote: onClipEvent (load) {
grav = 0;
}
onClipEvent (load) {
this._y += grav;
grav++;
}
idk whats wrong? The mc should have gravity but doesnt

okay, the only prob. i se, is that the second line of code (2nd onClipEvent) it is supposed to say:
onClipEvent(load){
grav = o;
}

onClipEvent(enterFrame){ <------------------------ you have 2 put an 'enterFrame' instead of 'load'
this._y += grav
grav++
}


BBS Signature
KynetiK-27
KynetiK-27
  • Member since: Jul. 23, 2006
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to grav code 2009-01-22 13:35:40 Reply

eh?

onClipEvent(load){

// Initial Speed
VelX = 0 // speed that MC will move horizontally (positive = right, negative = left)
VelY = 0 // speed that MC will move vertically (positive = down, negative = up)

// Forces
Gravity = 1 // downward pull
Friction = 0.9 // rate that speed slows down
Terminal_Vel = 20 // maximum downward speed

}

onClipEvent(onEnterFrame){

// Friction - here we slow down the MCs horizontal motion and make it come to a complete stop
if(Math.abs(VelX)>=1){
VelX *= Friction
} else {
VelX = 0
}

// Gravity - here we pull the MC down until it reaches its terminal velocity
if(VelY<Terminal_Vel){
VelY += Gravity
}

// Make MC move according to speeds
this._x += VelX
this._y += VelY

}

micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-22 18:52:54 Reply

lol i didnt see that! i cant believe i over looked it! thx guys


...

BBS Signature
micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-22 18:55:32 Reply

nvm still doesnt work

onClipEvent (enterFrame) {
	grav = 0;
}
onClipEvent (enterFrame) {
	this._y += grav;
	_root.grav++;
}

...

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to grav code 2009-01-22 18:59:11 Reply

At 1/22/09 06:55 PM, micky315 wrote: nvm still doesnt work

onClipEvent (enterFrame) {
grav = 0;
}
onClipEvent (enterFrame) {
this._y += grav;
_root.grav++;
}

Lol, you need to keep the "grav = 0" part inside the load event...

You set grav back to 0 each frame.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
LostVoices
LostVoices
  • Member since: Mar. 9, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to grav code 2009-01-22 19:15:36 Reply

omg HAHA so funny

do this dude

onClipEvent (load) {
	grav = 0;
}
onClipEvent (enterFrame) {
	this._y += grav;
	_root.grav++;
}

otherwise the way you have it grav is always 0
it enters the frame sets grav to adds 0 to the _y position adds 1 to grav and then goes back to setting grav to 0


awww

DanBomer
DanBomer
  • Member since: Apr. 1, 2006
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to grav code 2009-01-22 19:16:18 Reply

onClipEvent (load) {
	grav = 0;
}
onClipEvent (enterFrame) {
       grav++;
	this._y += grav;
}
</thread>

BBS Signature
micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-24 15:14:15 Reply

thanks it worked and i see the problem now but how do i make this have contact with the ground mc?


...

BBS Signature
micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-24 16:34:03 Reply

lol


...

BBS Signature
Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to grav code 2009-01-24 16:38:58 Reply

At 1/24/09 03:14 PM, micky315 wrote: thanks it worked and i see the problem now but how do i make this have contact with the ground mc?

You stop getting people doing your coding and look at tutorials!

Super-Yombario
Super-Yombario
  • Member since: Mar. 16, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to grav code 2009-01-24 16:39:12 Reply

Argh, don't bump like that >:(

if(_root.ground.hitTest(_x, _y, true)){
grav = 0;
}else{
grav ++;
}
BillysProgrammer
BillysProgrammer
  • Member since: Sep. 17, 2008
  • Offline.
Forum Stats
Member
Level 16
Gamer
Response to grav code 2009-01-24 16:48:18 Reply

You could also write a function.

Example:

Main Timeline

function makeGravGoNow() {
    if(grav < maxGrav) {
         grav ++
     } else if(grav >= maxGrav) {
         grav = maxGrav;
     }
     player._y += grav;
}

Player Code

onClipEvent(load) {
     grav = 0;
     maxGrav = 12;
}
onClipEvent(enterFrame) {
     if(this.hitTest(_root.ground)) {
          grav = 0;
     } else if(!this.hitTest(_root.ground)) {
          makeGravGoNow();
     }
}

Thats just a example, ud change it around to meet your needs. BTW, player is the instance name of the mc your targeting.

micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-25 10:36:27 Reply

i got a code from a ut but it still aint workin

onClipEvent (load) {
grav = 0;
}
onClipEvent (enterFrame) {
grav++;
this._y += grav;
}
onClipEvent (load) {
if (level.hitTest(_x=(_width/2), _y-(_height/2), true)) {
_x -= speed;
}
if (level.hitTest(_x=(_width/2), _y-(_height/2), true)) {
_x += speed;
}
if (level.hitTest(_x, _y-(_height), true)) {
grav = 3;
}
}


...

BBS Signature
Deathcon7
Deathcon7
  • Member since: Oct. 1, 2003
  • Offline.
Forum Stats
Member
Level 21
Writer
Response to grav code 2009-01-25 10:48:25 Reply

Remember that when you use a clip event handler, when set to load it's only going to run once when the mc is loaded onto the stage. If you use the enterframe condition, then it's going to run every frame so long as the mc is on the stage. What this means is, if you want to check something every frame, you need to use enterFrame. In this case you want to check to see if the clip is touching the ground, you would use enterFrame. If you're loading the grav variable, you'll load it in the load condition because you only need to load it once. See what I mean?

micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-25 21:00:47 Reply

i chaged the laod to enterframe but no luck


...

BBS Signature
Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-26 06:27:20 Reply

onClipEvent(load){
grav = 0
}
onClipEvent(enterFrame){
if(_root.stage_mc.hitTest(this._x,this._y,true)){
grav = 0
} else {
grav ++
}
}

that should work. stage_mc is your level/stage MC's instance name


AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature
micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-26 08:53:33 Reply

didnt work....


...

BBS Signature
micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-26 16:22:44 Reply

bump..


...

BBS Signature
Cojones893
Cojones893
  • Member since: Mar. 9, 2003
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to grav code 2009-01-26 16:55:06 Reply

You obviously need to learn actionscript. Go read some tutorials on how to use clipEvents and variables.

micky315
micky315
  • Member since: Aug. 2, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to grav code 2009-01-26 20:10:13 Reply

At 1/26/09 04:55 PM, Cojones893 wrote: You obviously need to learn actionscript. Go read some tutorials on how to use clipEvents and variables.

its just a simple code to stop gravity, i understand it but its not working


...

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to grav code 2009-01-26 20:13:42 Reply

Maybe you should deal with something simpler, you're obviously in over you head. Better to build up your skills before approaching this problem.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
Deathcon7
Deathcon7
  • Member since: Oct. 1, 2003
  • Offline.
Forum Stats
Member
Level 21
Writer
Response to grav code 2009-01-26 20:14:50 Reply

At 1/26/09 08:10 PM, micky315 wrote: its just a simple code to stop gravity, i understand it but its not working

If it's so simple, why can't you get it to work? Don't underestimate Actionscript. Just because you think it's simple doesn't make it so, especially if you don't know what you're talking about. Go back to some other tutorials and start from there. Try using AS: Main, there's at least 10 different tutorials on platforming and making games.

KynetiK-27
KynetiK-27
  • Member since: Jul. 23, 2006
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to grav code 2009-01-26 20:17:04 Reply

A How is it 'not working' ? It could 'not work' in several ways. What is it actually doing?

B Try taking out the shapeflag in the HitTest and see if that works.