Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / I can't make sprite collision work properly.

Author
Message
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 6th Dec 2009 03:39
I got a sprite moving around and falling with gravity, but it sticks to walls and floors, so it can only move in the air when it's not touching anything.

I don't understand how to make it walk along the ground and not stick to walls
Multi Programmer
14
Years of Service
User Offline
Joined: 6th Dec 2009
Location: Kansas City,MO
Posted: 6th Dec 2009 20:12
If you can post your code, I might be able to help.

"Never give up, because in the end you'll find you achieve greatly."
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 9th Dec 2009 04:12
Here is my code for collision for the player. vx and vy are the velocity. What this does, is simply check for collision, takes that sprite number and finds the tile with that number, if that tile is solid ("1"), then there is collision.

I just don't get how to make the player able to run on ground and not stick inside walls when running into them.

haliop
User Banned
Posted: 10th Dec 2009 11:57
i didnt much understand the code
but
i know this
when i was programming in 2D i remmber that
once collision accurd you cant move cause youre stuck
and the If Collision stops you.

what i realized is that
once there is a collision , in order to stop the collision
you must give the Player Sprite or any other sprite that you want it to keep moving , is
+ 1 to the X value or pherhaps a -1 cause youre probably coming from the left , actually , you need to "push" your sprite a bit backwards from the Direction it comes.
now , thats give your sprite \ player \ enemy or whatever entity
the "non collision" , cause you have just pushed it in the opposite direction so the Collision is gone.
i hope this can help
try this , and come back if you have more questions

nadav.
haliop
User Banned
Posted: 10th Dec 2009 12:01
about Ground and Walls
if



__________________

this is your ground, a simple method is to put your sprite on a +1 Y above it, now when your "falling" due to gravity , wait for the collision and then give it a +1 Y, so it will stuck on the ground but just for one milliSec.

and walls:

if this is you wall

|
|
|
O --> |

then again wait for the collision , it will stuck and then give it
a -1 from the direction you came
logicandchaos
15
Years of Service
User Offline
Joined: 22nd Sep 2009
Location:
Posted: 14th Dec 2009 17:03
hey i have had a lot of problems with the built in collision detection as well, i read that dbSpriteCollision() returns 1 if sprites are overlaped and dbSpriteHit() returns 1 if sprites are just touching, i'm not sure about this, because i had problems with both and now i found out that it doesn't work right with rotated sprites, anyways hope i helped

logicandchaos

Login to post a reply

Server time is: 2024-11-20 07:35:56
Your offset time is: 2024-11-20 07:35:56