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.

DarkBASIC Professional Discussion / Pixel Perfect Collision by Cloggy...Help needed.

Author
Message
Iceman
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location:
Posted: 20th Dec 2010 05:41 Edited at: 20th Dec 2010 05:43
Ok, I did send Mr Cloggy a few emails over this, but unfortunatly he didnt get back to me so Im asking on the forum instead.

I was looking on the forum for a bit of code to do the collision for a "Tanks" like game Im doing, when I found this from cloggy...



I have been using this little code that he made that checks collision between 2 sprites (one sprite is the background and the other the user movable sprite) and it works great, ... the user sprite moves over the other sprite ala-platform, but I have a prob with it.

When it touches the second sprite high up it "jumps" through the second sprite and on to the next level.

To make it a bit clearer.............. look at the picture


You can see the player sprite. He is standing (as he should) on a platform which is of cause part of sprite 2.
If I move him from the BLUE starting area, when he gets to the GREEN section, a small collision occurs on the sprites "head" because of the underhang from the platform above.

As soon as he hits this small underhang he immediately "jumps" to the RED position.

Now, I am happy with him moving about on the platforms, and going up inclines etc but what I need to stop him doing is "jumping" upwards when he either gets hit like above OR if he comes to a VERY steep incline (like a wall). lol

I dont know enough to do this with Cloggys program, but can anyone here tell me what I need to do to get it to stop doing the "jump" thing?

One other question.... using Cloggys prog, could the user sprite be animated??
I guess if that is not poss then I will have to leave it and find another bit of code to use for the collision.

Oh, and just to save me posting again... If ANYONE knows of a bit of code to do what I want, please post it here or point me to it cos I really need to crack on with this game.

Thanxs
Madscientist
14
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 20th Dec 2010 15:07 Edited at: 20th Dec 2010 15:07
Your problem is that with that code, it's doing:
If collision then move player up.
You want:
If collision then move player to open space.
Since your player will be moving into the other sprite when it is going a certain X velocity and Y velocity, if you set them negative when there is a collision, they will move out of the collision point to where they originally were.

This is untested but should work.

My computer surpasses all the technologies of the day. What computer do I have?

Iceman
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location:
Posted: 21st Dec 2010 19:58
Thanks Madscientist, but it dont work

The guy just hovers near the top of the screen.

Well it looks like no one on here knows, and I cant get in touch with cloggy, so I will have to try something else now...shame that as the routine works a treat.

Thanxs for trying tho Mad.
Madscientist
14
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 21st Dec 2010 23:24
Wait don't give up, I've reworked my code to get it 75% working.
Just give me a little time and I'll get it perfect.
Try this for now though.



My computer surpasses all the technologies of the day. What computer do I have?

Iceman
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location:
Posted: 23rd Dec 2010 03:00
Well now Madscientist, thats a lot better, but here is the prob.

If I jump upwards and it hits something, then it does NOT jump through the platform and just falls back to the ground.... that part is great.

But If I am pressing left or right at the time I jump then it does jump through the platform. Also if i am just pressing left/right and i hit that small bit at the botton of the screen, it jumps up too.

I have put an exe for you to download so that you can test it yourself and see.

Attachments

Login to view attachments
Madscientist
14
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 23rd Dec 2010 03:41
I know exactly what you mean
Quote: "75% working"

I just got to tweak those errors. My main problem (or yours rather) is how to calculate the new positions after collision is detected. When the object collides at X velocity and Y velocity, I have to figure out which velocity to set to 0 and which to stay the same. But I'm trying to do this without checking for collision on all 4 sides, that way it can be implemented on shapes other than a rectangle. If anyone else on these forums knows how, feel free to post.

My computer surpasses all the technologies of the day. What computer do I have?

Iceman
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location:
Posted: 1st Jan 2011 19:22
Hey there Mad.. any luck m8?

If not, then I will have to look at another way as I cant wait much longer.

Login to post a reply

Server time is: 2024-05-18 06:47:41
Your offset time is: 2024-05-18 06:47:41