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 / Where is the collision happening?

Author
Message
Scotty1973
AGK Backer
13
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 18th Jun 2014 04:08
Hi

This is a awkward to explain question so please bear with me.
Im working in 2D with 2 object A(a rectangle, like in pong) and B( a ball) for this purpose.

Imagine A at centre of screen as an arrow facing 0 degrees
Now A can rotate through 360 degrees.

Using the collision detection I can detect a collision between both A and B.

If A id 0 degrees i can tell if its a top or bottom, right or left collision.

My problem is if A rotates X degrees, using the x,y coordinates of B to see where collision occurred doesn't work.

I want to know where B hits A at any rotation(ir top, bottom , left and right, also how far along A that B hits. I've been thinking of Sin and Cos as a rotation of Bs x,y Coordinates but I'm struggling badly(long time since I left school lol)


A
B or A B
AAAAAA A
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Jun 2014 09:11
Maybe the "GetSpriteXFromWorld" and "GetSpriteYFromWorld" commands will help?
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 19th Jun 2014 03:34
http://www.physicsclassroom.com/class/refln/Lesson-1/The-Law-of-Reflection
Are you looking for the angle of reflection? If so check out the above for an understanding of it. It's a little messy.
I tried wrapping my brain around it a little while ago, but then I got distracted and never finished it. I did have a pong program that did the calculation, but apparently I've lost it.
Hope this helps.

Scotty1973
AGK Backer
13
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 19th Jun 2014 11:55
Thanks Bax found a few commands that are useful, they are:-


getSpriteDistance()

getSpriteDistancePoint1X()
getSpriteDistancePoint1Y()

Found if I call these straight after collision has been detected it will give me the collision point.

Cheers Naphier will look into that. Like I say it's been a while in since school lol
IronGiant
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 27th Feb 2012
Location: the great state of madness
Posted: 19th Jun 2014 17:00
Not sure if this is what you are looking for but here is a link to poolball physics routine written in blitzbasic, blitzmax and monkey that might help you with angled collisions.

http://www.blitzbasic.com/codearcs/codearcs.php?code=415#comments

It's Bird! , It's Plane!, No its a rocket powered Squirrel holding some acorns and a smile!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Jun 2014 17:00 Edited at: 19th Jun 2014 17:01
Quote: "Thanks Bax found a few commands that are useful, they are:-


getSpriteDistance()

getSpriteDistancePoint1X()
getSpriteDistancePoint1Y()

Found if I call these straight after collision has been detected it will give me the collision point.

Cheers Naphier will look into that. Like I say it's been a while in since school lol "

That's not a bad way to do it. If you're using physics sprites you could use setSpritePhysicsIsBullet to increase the accuracy of those commands to an actual impact. It turns on continuous collision detection for the sprite.
Scotty1973
AGK Backer
13
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 21st Jun 2014 00:57
Quote: "That's not a bad way to do it. If you're using physics sprites you could use setSpritePhysicsIsBullet to increase the accuracy of those commands to an actual impact. It turns on continuous collision detection for the sprite."


Trying to avoid the physics commands.

Now I know how to get point of collision is there any way I can kinda glue the 2 sprites together at that point so that if I move/rotate the main sprite the other stays in the relative position?
I guess its like a limb to the main sprite and did notice a post from Bax answering about limbs and mentioning this function
rotateSpriteAbout function
Been unable to locate any other post in the forum.

Thanks for your help people

Login to post a reply

Server time is: 2024-11-25 06:33:26
Your offset time is: 2024-11-25 06:33:26