[DRAGONSTAR] GAME MAKER HELP NEEDED: PLAYER COLLISION

Posts

Pages: first 12 next last
So this is for any of you Game Maker experts out there!
Note: using GM 8.1 Pro Version

So, I recently added the standing and running sprites for Orthum (character for the game. Btw, alpha launching soon! XD) in place of the Link Sprites(from legend of zelda) I was using as placeholders. The Orthum sprites are larger than the Link Sprites, so I figure that might contribute to the issue, but atm the Character will randomly freeze when landing on a platform, either from falling onto it or jumping onto it. The original sprites worked fine, and I'm using the same method for collision (a full image rectangle mask), but it still freezes up. I've asked the GM community, but they won't reply for some reason. Heck, nobodies even viewed it! I feel rejected..... T_T Just kiddin. Anyways, any help from you GM masters out there would be helpful! I'm only three months into seriously working with GM, so I'm experienced but not to the point of perfection. Thanks in advance guys! :)
can you post your collision code (as well as any other code you think is prudent)?
Well for my basic ground and platform collision I'm mostly using D&D. When the space below the character is free, it's sets Gravity to 2 in direction -90 (or 270, whatever floats your boat). If the space is not free, sets gravity 0 in direction 0. ATM I'm trying to remember everything off the top of my head cause I'm AFK. Lol. Any other things you might need to know?
When I get back ill just post the current Version and let you look at it.
yeah, just put it in your locker or something and i'll take a look at it
making the collision conditionals match the gravity (i.e. checking if there's a collision at 0,2 instead of 0,1) solved it for me, though there is kind of a floating issue i can't figure out right at this moment. i also deleted the set vertical speed commands in release-left and release-right.

also, as an aside, you're running way too many instances for it to be viable on a large scale. your main problem with the instances is that all the ground pieces are represented as objects - if you make your ground sprites into tiles and then just make some generic collision solids for your character to run into, you'll probably cut the instance count down by 1/2 or more.

you also may want to pick up GML - in the end, you'll be able to do a lot more and it'll be a lot simpler. it's hard to really tell what's going on in this with D&D and it'll just get more and more complicated the more you add to it.
It's been a while since I last made a platformer in GM but you could try putting a collision check in the wall or floor which sets x and y to previous.x and previous.y
Can't help any further sorry :(

Edit: Because I'm on mac, otherwise I would have a look for you
If the floating issue is with the jump, it's just a matter of setting the gravity differently.
May or may not help but if you use y+1 or +gravity to check whether or not to stop try changing it to +vspeed
I think I'm already using vspeed for another check, but I'll look back over it and work through and see what I can come up with.
I'll redownload Game Maker when I next boot windows and have a fiddle myself. I'll also see if I can find the old tutorial on youtube I used years ago.

Edit: May be a silly question but what is the mask sprite of the player object? Make it the same as the walls and it should go more smoothly. (or at least a fraction of the size eg/ wall is 16x16, 8x8 or 4x4 will work for the player mask)

Edit 2: http://www.youtube.com/watch?v=StlP7a69TNk&list=UUEmbL20VPM8phSETC4n_fHw&index=15&feature=plcp

there you go. It's a series of 8 or so and shows the basics of gml as well as platforming with good collisions.
Awesome. I'll give it a look! And I'll see if I can experiment with some different mask sizes to see how that plays out.
Yeah masks are always helpful cos it means you dont have to worry what your character sprite looks like then.
alright. I'm still lost. I've gone through multiple ways of not only jumping but character movement as well. Now the entire thing is screwed up. I'm completely stummped. And my computer is so slow that the YouTube videos are constantly hanging up, and it says those videos arent available on my iPhone. :/
Ah snap thats not good.

I'll try and give a brief overview of the basics of the vid for you then.

It's not explained in the video what everything does so I'll explain each bit for you aswell.

Make 2 objects:
obj_solid - simple 16x16 black box for sprite/no mask tick solid in object options
obj_player- use a 16x16 other colour block for the mask (and sprite for now)


Player step event: (code)
if place_free(x,y+1)

{
gravity = 0.5
}
else
{
gravity = 0
}
gravity_direction = 270

This checks if you are in the air or not and sets gravity accordingly then sets gravity direction no matter what.

Benath that put:
if vspeed > 10

{
vspeed = 10
}

This stops you going too fast (can sometimes be the cause of going through blocks)

Now onto left/right movement, beneath the above:
if keyboard_check(vk_right) && place_free(x+4,y)

{
x += 4
}
if keyboard_check(vk_left) && place_free(x-4,y)
{
x -= 4
}

This checks for left and right arrows being pushed as well as for a place to move, then moves if it can.

Now your jumping code:
if keyboard_check(vk_up) && !place_free(x,y+1)

{
vspeed = -7
}

Checks if jump is pressed and that the place below you is NOT free (that's what the ! means) so you can't repeatedly jump. Then it changes your vspeed, and gravity will kick in due to the first bit of code we made.

Now make a collision event in obj_player for when it touches obj_solid and put this code.
if vspeed > 0 && !place_free(x,y+vspeed)

{
move_contact(270)
}
vspeed = 0

This makes it so that if you touch the floor from above whilst falling, you will be place back on top of it without getting stuck in it, then changes your vspeed back to 0.


And there you go, I think move_contact was the one I meant to say in the first place :/

Hope this helped you.
Will it work with larger sizes as long as the sprites for the ground and player are the same size?
It should work for any size, so long as both sizes are divisible by 4 (or whatever number you set in your movement bit. The player doesn't necessarily have to be the same size as the wall either, if the player mask is bigger than the sprite though you could end up with some odd collisions (in terms of colliding before the visible sprite has)
Alright. It works now! Thanks a lot! I made some of my own adjustments so that it works properly with the room. :)

I may have another question in just a bit. Depending.
Alright no problem, If you want help with slopes or anything I can give it a shot.

Also for knowing what sprite to show here is my method:
obj_player created event:
player_movement = 'idle'

player_facing = 'r'

facing shows which direction and movement is the action, eg/ walk jump fall and idle.

To check for the walk pose. Go to the movement bit and change it a bit:
if keyboard_check(vk_right) && place_free(x+4,y)

{
x += 4
if player_movement != 'jump' || player_movement != 'fall'
{
player_movement = 'walk'
}
player_facing = 'r'
}

if keyboard_check(vk_left) && place_free(x-4,y)
{
x -= 4
if player_movement != 'jump' || player_movement != 'fall'
{
player_movement = 'walk'
}
player_facing = 'l'
}


For falling put this at the bottom of the step event:
if vspeed < 0

{
player_movement = 'jump'
}
if vspeed > 0
{
player_movement = 'fall'
}


For idle, make new events for release left and right keys and put this in both:
if player_movement != 'jump' && player_movement != 'fall'

{
player_movement = 'idle'
}


In the endstep event you can then check these variables and change the sprite accordingly.
Pages: first 12 next last