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.

2D All the way! / Sprite collision when rotating

Author
Message
Zyronagon
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location: USA
Posted: 1st Mar 2010 04:06 Edited at: 1st Mar 2010 04:07


I do realized that the code is quite unorganized, and I'm slightly embarrassed by this. I'm testing out the shooting collision before I add any enemies or background (zombie game, btw. ). For some odd reason, the collision is screwing up. Like, really badly. Here's some pics to see what it's doing.




I have no idea what's going on. Help please?
LBFN
16
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 1st Mar 2010 04:45
I took a quick look at it. I wonder if you are leaving the word "hit" on the screen long enough to see it. After you print it, sync and put in a one-second delay to see if this is the problem.

Zyronagon
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location: USA
Posted: 1st Mar 2010 22:44
I realize what's happening now. The sprite is rotating, but the collision isn't. So...
Disregard all of the first post and answer this (hopefully) simple question: How do I make a sprite's collision rotate WITH the sprite?
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 2nd Mar 2010 14:31 Edited at: 23rd Aug 2010 01:13
Quote: "How do I make a sprite's collision rotate WITH the sprite?"


Dbpro doesn't support this. There are some home grown solutions on the forums, but you'll most likely have to dig them out of the bowels of the forums.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Mar 2010 15:50
Have a look at some 2D line-line intersection algorithms and such, that's your best bet. Some people use pixel-perfect collision but it's very intensive and isn't really necessary.
Zyronagon
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location: USA
Posted: 2nd Mar 2010 22:58
Thanks anyways. I guess I'll be going to the bowl's now. lol
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Mar 2010 15:29
Yeah, line to line collision is really good, not just for this - line intersection detection can help in all sorts of techniques.

What I would do, is store a series of points, a dot to dot line around your sprite. But I would store the angle and distance from centre instead of the actual coordinates. With that, it's incredibly simple to allow for rotation. It's not straightforward, but it's a great technique to know, it's especially good for bullet collision.


Health, Ammo, and bacon and eggs!
Zyronagon
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location: USA
Posted: 3rd Mar 2010 23:00
I think I might change from using a line as the bullet to making individual (round) bullets. That should save me some trouble; I can insert the sprite, rotate it, and then use the MOVE SPRITE command to move the bullet forward in the proper direction that was determined by the ROTATE SPRITE command.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Mar 2010 13:23
Not a good idea .

For one thing, how will you check the inbetween positions. Most bullets move too fast for that technique to be effective.

With line to line collision, you just use the current and previous location of each bullet to make the line, and so it's very robust - anything in the bullets path can be easily checked once the system is in place.

I mean, what if you move the bullets at 10 pixels per loop, and you have a wall that is only 8 pixels thick - bullets could pass right through.

I have to look at this technique for an iPhone game, so maybe I can make a little tutorial and editor for it, make it a bit easier to adopt - I really think it's the best option and you should persevere with it, don't settle for a lesser technique for the sake of simplicity, simplicity is nothing without function.


Health, Ammo, and bacon and eggs!
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 4th Mar 2010 14:32 Edited at: 4th Mar 2010 14:33
Whether you use instant bullets or not, you should definitely use ray casting (line to line collision) as Van B suggests, as it is efficient and accurate.

And besides, learning the more complicated (and appropriate) techniques will help you more in future projects.
Zyronagon
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location: USA
Posted: 4th Mar 2010 23:15
Okay, thanks. I'll look into it.

Login to post a reply

Server time is: 2024-03-29 14:03:02
Your offset time is: 2024-03-29 14:03:02