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.

AppGameKit Classic Chat / collision question

Author
Message
pjsmith67
8
Years of Service
User Offline
Joined: 2nd Feb 2016
Location: Nebraska, USA
Posted: 24th Oct 2016 21:21
Ok, hopefully I can describe this well enough... I am working on a game, or trying to, where I have a ball that moves up and down continuously, changing directions when it hits an obstacle which for now is a wall. The problem is that I want the user to be able to move the ball horizontally as well with the horizontal movement stopping when it hits a wall. I thought this would be easy enough but, alas, no such luck. The problem is how do I tell if the wall it hits is the left side, right side and/or the top/bottom? I've tried using different sprite groups and ray casting. I'm not currently using physics. Is there a way to tell which side a collision occurs on that I'm not seeing here? I'm just looking for a pointer in the right direction. I've been fighting this for the better part of a month now. :-(

Thanks,

Phil
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 24th Oct 2016 22:26
Hi there.

There's a few different ways to do this - with or without physics.
Without knowing the extent of your intentions (which is important, as certain methods may add limitations or make other things you want to do later impossible) I would presume at first that you want to know what part of the ball is hitting the wall (or something) so you can affect the ball appropriately?

One way would be to have some dummy sprites which are invisible, but are the hit areas you want to use - so you would make a sprite which represents each quarter of your circle/ball and test for hits on that. You would need to set the shape of the sprite with SetSpriteShape( iSpriteIndex, shape ) - where shape=polygon. Move those sprites the same as your actual ball so they replicate it's location.

Another more precise trick could be to use a dummy (smaller) circular sprite which can be moved around inside the other circle in a 2-pass collision check. In a way, this is a circular version of the old school per-pixel check mechanic.
If you make a circular collision check with your original ball and it passes, then you run the 2nd phase which is to see which part of the ball collided. To do this, you would rotate (and test) the smaller ball which is rotated on or around the orbit of the larger ball with some simple maths. When this hit checks, you have the angle of the ball collision, which you can use for whatever you need.
You would probably not check all 360 degrees, but whatever precision you want to follow is up to you. The size of the inner ball compared to the larger one would be relative to how many pixels your ball moved per check, so you'd always be sure of getting a 2nd pass result.


pjsmith67
8
Years of Service
User Offline
Joined: 2nd Feb 2016
Location: Nebraska, USA
Posted: 25th Oct 2016 05:30
Thanks for the tip. I'm experimenting with dummy sprites now. Still having some issues but at least I'm making some progress.

Phil
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 25th Oct 2016 20:52
I'd probably look at the balls velocity when collision is detected. If the ball is moving right when it hits a wall, you can be fairly sure it has hit the left side of a wall.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
pjsmith67
8
Years of Service
User Offline
Joined: 2nd Feb 2016
Location: Nebraska, USA
Posted: 25th Oct 2016 22:03
Yes, exactly. I'm using a combination of the two and finally got it working last night! Yay!

Thanks!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 26th Oct 2016 08:53
Why not just use the 2d physics system?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 26th Oct 2016 11:58
if you using a ray you get a hit position, you will have the ball center position, and you will get the surface normal.
at a normal collision i think you can use this:
GetSpriteDistancePoint1X GetSpriteDistancePoint1Y
GetSpriteDistancePoint2X GetSpriteDistancePoint2Y
ATanFull( x, y )
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
pjsmith67
8
Years of Service
User Offline
Joined: 2nd Feb 2016
Location: Nebraska, USA
Posted: 26th Oct 2016 18:56
I wasn't able to get the ball to move at a constant speed when bouncing up and down with physics,. I know there probably is a way, I just haven't had time to dig into AppGameKit as much I would like over the last few months.

Same thing with ray casting. I couldn't get it work the way I wanted/thought it should. Again, probably my inexperience with it.

Even though I bought it back in January, I just haven't had time to really work with AGK. I need to take a vacation from my real job so I can.

One think I have been able to do is write my own tile map editor. Why? Because I like writing my own tools so they work exactly the way I want them to.

But I really appreciate all the helpful hints I've gotten on here.

Phil

Login to post a reply

Server time is: 2024-11-25 02:05:17
Your offset time is: 2024-11-25 02:05:17