The Daily Click ::. Forums ::. Klik Coding Help ::. Change direction of Gravity
 

Post Reply  Post Oekaki 
 

Posted By Message

MAG415



Registered
  29/12/2006
Points
  6
18th January, 2007 at 02:02:29 -

Im still a noob and i was wondering whether any of you guys know how to change the direction of gravity in MMF2. Im making a side scroller/platformer, i want it so my character can walk on walls.
-Thanks


 
n/a

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
18th January, 2007 at 03:47:11 -

Yeah, I've done it. But you'd need a good understanding of custom movement engines first, so you might want to do some research on those first.

The basic idea is that you have a variable that tells the player in which direction he should fall. So let's just say I've got three alterable values, called Gravity, X velocity and Y velocity:

* Gravity("Player") == 0
- Add 1 to Y velocity("Player")

* Gravity("Player") == 1
- Subtract 1 from Y velocity("Player")

* Gravity("Player") == 3
- Add 1 to X velocity("Player")

* Gravity("Player") == 4
- Subtract 1 from X velocity("Player")

* Always
- Player: Set X position to X("Player") + X velocity("Player")
- Player: Set Y position to Y("Player") + Y velocity("Player")

So if Gravity is 0, the player should fall downwards, if it's 1 he will fall upwards, etcetera. All you need then is collision detection and jumping and stuff.

 
n/a

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
18th January, 2007 at 05:46:03 -

Alternatively, you cando it quicker with 2 gravity variables:

* Add (Speed * XGrav) to X Velocity("Player")
* Add (Speed * YGrav) to Y Velocity("Player") (bearing in mind (0,0) is the top left, therefore, if you add 1 pixel you go down the screen)
The speed is the number of pixels/frame you want to move. I.E if 2, you will move 2 pixels for each frame.

*Some events that flip Gravity*
- Set Xgrav to +/- 1
- Set YGrav to +/- 1

If +1 the gravities will be the same, if -1 the gravities can be reveresed.
Alternatively you can randomly increase the size of gravity by changing the 1 to 2, 3, etc.
Then do
* Always
- Player: Set X position to X("Player") + X velocity("Player")
- Player: Set Y position to Y("Player") + Y velocity("Player")

As Axel said.

 
My signature is never too big!!!

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
18th January, 2007 at 07:41:32 -

Ah, yeah. Do what Joe said, it's cleverer.

 
n/a

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
18th January, 2007 at 15:31:42 -



 
My signature is never too big!!!

The Chris Street

Administrator
Unspeakably Lazy Admin

Registered
  14/05/2002
Points
  48488

Game of the Week WinnerClickzine StaffAcoders MemberKlikCast StarVIP MemberPicture Me This Round 35 Winner!Second GOTW AwardYou've Been Circy'd!Picture Me This Round 38 Winner!GOTM December Third Place!!
I am an April FoolKliktober Special Award Tag
18th January, 2007 at 18:46:59 -

Also, activating and deactivating groups is strongly advised.

 
n/a

Reno



Registered
  11/01/2005
Points
  906
18th January, 2007 at 19:44:47 -

just create your own custom movement then for diffrent gravity modify the XY variables.

 
Reborn Again

MAG415



Registered
  29/12/2006
Points
  6
18th January, 2007 at 21:06:45 -

ok...I'm one confused noob....
Can you please explain it to me by like telling me what events then the result?
And when you say velocity, i cant find it, do you mean speed? Then X Gravity "player", i can only change the Gravity, not X gravity or Y gravity.

DAMN THOSE STUPID TUTORIALS TEACH YOU NOTHING

Thanks

-Mr.Noob

Image Edited by the Author.

 
n/a

Bibin

At least 9001

Registered
  01/07/2005
Points
  308

Silver Cup WinnerGOTW Winner!Has Donated, Thank You!VIP Member
18th January, 2007 at 23:08:57 -

Uh, first you better learn about fastloop engines. Just, now, for your own good, click on your player, go to the movement tab, and with a bold and meaningful click, select "Static" as the movement type. Then, search "Fastloop engine" and you'll probably be able to find a good engine.

 
n/a

MAG415



Registered
  29/12/2006
Points
  6
19th January, 2007 at 01:33:40 -

Ok...i found out what a fastloop is and I already had fastloops in place in my game.

Image Edited by the Author.

 
n/a

MAG415



Registered
  29/12/2006
Points
  6
19th January, 2007 at 02:14:55 -

hahaha just found out that i've been creating my own custom movement engine from scratch when i could have used a generic platform engine, guess i'll just finish my engine... Then i found out what alterable values are, everything is so clear now!

Thanks for the help and thanks for not flaming on me on being such a stupid noob.

 
n/a

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
19th January, 2007 at 04:24:42 -

If I had TGF/MMF/etc I'd make you an example.

But I don't.

Though I have a DVD somewhere with TGF pro on it.

If I can find that I'll make you an example. (I'll try not to use any extensions. But this way the movement engine will be very limited.)

 
My signature is never too big!!!

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
19th January, 2007 at 10:28:05 -

"hahaha just found out that i've been creating my own custom movement engine from scratch when i could have used a generic platform engine, guess i'll just finish my engine... Then i found out what alterable values are, everything is so clear now!"

I strongly advise against that. There are so many ways to make a custom movement engine, that if you finish your engine, and try to figure out variables and fastloops afterwards, you might just have to rewrite your entire engine. It'd be a good idea to do it right, from the start.

X velocity and Y velocity are not attributes like the speed or acceleration things that you find under the active object's movement submenu in the event editor. X velocity and Y velocity would be variables, which practically means they're counters, or more specifically alterable values. In case you don't know what alterable values are; They are like normal counters, they are used to store numbers. Each active object has a number of alterable values (3 in TGF, 25 in MMF and unlimited in MMF2). The variables I named X velocity and Y velocity would be used to store the current X (horizontal) and Y (vertical) speed of the object. So they'd provide pretty much the same function as the speed attribute, except it'd give you more control of the movement.

So, to move your player, you add the value of X velocity to the player's X position, and the value of Y velocity to the player's Y position. It's not that hard to understand, really. So, after that, you can manipulate the player's speed freely, just using those two variables. So, to apply gravity to the object, you'd obviously add/subtract from either X velocity or Y velocity, to accelerate the player in any particular direction.

So, to get the directional gravity effect, you could do like Joe said, and add two more variables to the object; X gravity and Y gravity. Then, just always add the value of X gravity to X velocity and Y gravity to Y velocity. After that, you can manipulate the gravity easily, just by changing the value of X gravity or Y gravity. For example, setting X gravity to -1 would make the player fall to the left, while setting Y gravity to -1 would make him fall upwards, and Y gravity to 1 would give you normal gravity.

Circy's idea, to use groups and activate/deactivate them depending on the gravity, would maybe seem easier to code, but in the end, you'd only end up with four times the amount of code, for the same effect.

Also, try DC searching for "Custom movement engine". I don't know where Bibin got the term "fastloop engine", because it really doesn't have much to do with directional gravity or custom platform movement engines.

http://www.create-games.com/cs_search.asp

 
n/a

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
19th January, 2007 at 13:34:03 -

Couldn't find it.

Oh well.

It's easy to do anyway.

 
My signature is never too big!!!

MAG415



Registered
  29/12/2006
Points
  6
19th January, 2007 at 22:10:41 -

"I strongly advise against that. There are so many ways to make a custom movement engine, that if you finish your engine, and try to figure out variables and fastloops afterwards, you might just have to rewrite your entire engine. It'd be a good idea to do it right, from the start."

Starting over won't be a problems since i have like 2 events that acutally work how i want it.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click