Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Platform ~ Gravity Issues. Help please. FIXED  (Read 933 times)

0 Members and 1 Guest are viewing this topic.
Platform ~ Gravity Issues. Help please. FIXED
« on: August 16, 2008, 08:27:38 pm »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
I am working on a platformer engine for GM 6.1 and for use in a project called Undercroft.
Everything I have thus far is handled via code.

I have an issue though when you try to step off the ledge...you don't fall. You keep walking on air until you press Z to jump.

Here's the code.  Maybe you guys can figure it out.
Code: [Select]
{
//this set of code will, in the end, contain every action for Link
//Platform Engine WIP by Theforeshadower
//Do not claim as your own

//temporary gravity engine
if jumping = 0
{
    if vect = 0 and distance_to_object(object1) > 5
{
    y = y + 4
    sprite_index = linkfallright
    fall = 1
    jumping = 0
}

else if vect = 1 and distance_to_object(object1) > 5
{
    y = y + 4
    sprite_index = linkfallleft
    fall = 1
    jumping = 0
}


else if distance_to_object(object1) < 5
{
    fall = 0
    jumping = 8
}
}
//end of gravity



//collision left and right
if direct = 1 and distance_to_object(object1) = 0
{
    x = x - 3
   
}

else if direct = 0 and distance_to_object(object1) = 0
{
    x = x + 3
   
}
//end of collision left and right


//movement left and right
if keyboard_check(vk_right)
{
    x = x + 3
    direct = 1
    vect = 0
   
    if fall = 0
{
        sprite_index = linkwalkright
        image_speed = .5
}
}

else if keyboard_check(vk_left)
{
    x = x - 3
    direct = 0
    vect = 1
   
    if fall = 0
{
        sprite_index = linkwalkleft
        image_speed = .5
}
}
//end of movement right and left

//stopping of movement
if keyboard_check_released(vk_right)
{
    if fall = 0
{
        sprite_index = linkstandright
}
}
else if keyboard_check_released(vk_left)
{
    if fall = 0
{
        sprite_index = linkstandingleft
}
}
//end of stopping


//jumping
if fall = 0 and keyboard_check(ord('Z')) and jumping > 0
{
    y = y - 6
    fall= 0
    jumping = jumping - 1
}
if keyboard_check_released(ord('Z'))
{
jumping = 0
}
//end of jumping



}
« Last Edit: August 17, 2008, 10:51:54 am by Theforeshadower »
Logged
  • Super Fan Gamers!
Re: Platform ~ Gravity Issues. Help please.
« Reply #1 on: August 16, 2008, 09:36:12 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
It would be easier to help if you provided a game file that others could download so others could run it and find it easier.  The way you write code though looks horrible to read and while the comments give the general idea, there are some variables that have ambiguous meanings. 

Since you said that when you press z to jump and that somehow fixes it in a way, then chances are something is not being set elsewhere or something.
Logged
Re: Platform ~ Gravity Issues. Help please. fi...
« Reply #2 on: August 17, 2008, 10:51:28 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
here in attachments...have fun.

With some advice from a colleague, I started from scratch.

The only things I don't care for is basically slow gravity but that can be fixed so bleh.
« Last Edit: August 17, 2008, 10:53:06 am by Theforeshadower »
Logged
  • Super Fan Gamers!
Re: Platform ~ Gravity Issues. Help please. FIX...
« Reply #3 on: August 17, 2008, 09:55:46 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Yeah, your code in that was not that great either.  Really, everything doesn't have to be in the step event.  The "direct" variable you were using was not really used, but I renamed it to the standard "direction" as that was the same thing - you also had a flaw in your code where "direct" for a right condition was checked at 90 which is up.  There were some places in your code that were redundant, your spacing and bracket use was terrible, etc.

I am not saying that mine is perfect because I did not feel like going back into it again and checking every little thing, but I made some improvements for the hell of it.

In mine, you can:
- Go left or right at by increments of 4 if you are on the ground or in the beginning of a jump.
- Only go left or right by increments of 3 when "landing".
- Jump only if you are on the ground.
- If you jump and there is a block above you that you would otherwise jump over in terms of height, you "stick" to it until the jump is over rather than fall instantly (to change this, you just have to change a few variables)
- I also changed the origin of the sprites, but changing that shouldn't do anything bad, I was just seeing if that was causing anything.

Anyway, the attachment is in a GMK file since I am on a computer that runs Vista as its operating system.  I could have made it a GM6, but that would have involved copying the download to a USB flashdrive, editing it on an old computer, etc.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.234 seconds with 42 queries.