Jump to content


Photo

Making a 2D Platformer: Character Won't Move


  • Please log in to reply
5 replies to this topic

#1 The Fire Commander

The Fire Commander

    GMC Member

  • New Member
  • 2 posts

Posted 29 April 2011 - 10:31 PM

Hi all! I'm currently learning how to code in GML, and I've done quite a few things in GML, so I'm not terrible at it and I'm not great at it, either. I wanted to make a quick platformer game for Easter, and I'm having a bit of trouble. I'm mostly using the action buttons and I have GM8 Pro.

I've already added all of the events that tell the character to move, jump, gravity, etc. However, I found a little, tiny problem. When my character is on the ground, he won't move, but he can jump. When you jump, the character is able to move while in the air, so it's not a problem with the left and right keyboard events, so I think it's a problem with the collision with block event. Here's the actions I put for collision with the Block:

move in direction direction at most 12 till a contact with solid objects
set the vertical speed to 0
execute code:

if right = true
sprite_index = spr_Character_Right
else
sprite_index = spr_Character_Left

The Block is solid and the character isn't. The Block doesn't have any actions or events.

I've made a few other platform games before and I never had this problem, so I'm not sure why this isn't working!

If I need to post the code of another event, just ask and I will!
  • 0

#2 Christa

Christa

    GMC Member

  • GMC Member
  • 267 posts

Posted 29 April 2011 - 10:37 PM

What is the mask of the character sprite? Is it a solid square box or is it the shape of the character? If it's the shape of the character, that's probably why.
  • 0

#3 The Fire Commander

The Fire Commander

    GMC Member

  • New Member
  • 2 posts

Posted 29 April 2011 - 10:48 PM

What is the mask of the character sprite? Is it a solid square box or is it the shape of the character? If it's the shape of the character, that's probably why.


I think it's the shape of the character.

Noob question: How do I set the mask to a solid square box? Never used masks before...
  • 0

#4 Awesomeness

Awesomeness

    GMC Member

  • New Member
  • 367 posts

Posted 29 April 2011 - 11:10 PM

I think it's the shape of the character.

Noob question: How do I set the mask to a solid square box? Never used masks before...


There's a button when you open the sprite that says "Modify mask." If you click on that you can adjust it.
  • 0

#5 Pie Crust

Pie Crust

    GMC Member

  • New Member
  • 14 posts

Posted 30 April 2011 - 01:08 AM

If it doesn't move, check the player's events.
If it isn't EXACTLY LIKE THIS, the player WON'T MOVE! You CAN add any other junk but make sure that these extremely important events are there.

<left movement key>
<change sprite to LOOKING_LEFT>
<If a position is collision free>
<Jump to position -4, 0>
<ELSE>
<If a position is collision free>
<Start a block>
<Jump to position -4, -8>
<Move contact in direction: 270; maximum: 8 against: solid objects>
<End a block>

<right movement key>
<change sprite to LOOKING_RIGHT>
<If a position is collision free>
<Jump to position 4, 0>
<ELSE>
<If a position is collision free>
<Start a block>
<Jump to position 4, -8>
<Move contact in direction: 270; maximum: 8 against: solid objects>
<End a block>

<jump key>
<If there is a collision at position>
<Set the vertical speed -10>

<Collision: WALL (or any object you want the player to bouce back. AKA: come back to the floor)

<Move to contact in direction direction with a maximum of 12 against solid objects>
<Set the vertical speed: 0>


If you don't understand some of this, tell me
-Pie Crust
  • 0

#6 Cocopuffs

Cocopuffs

    Now with more funny!

  • New Member
  • 652 posts

Posted 30 April 2011 - 01:24 AM

If you have Pro you can do:
image_xscale=1
or
image_xscale=-1
to flip the sprite, rather than having 2 sprites of every animation facing left and right.

On to your actual problem, it would help if we had the left/right event codes.

Also make sure that gravity is set to 0 when the player is above solid ground.

Good luck,
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users