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 / [SOLVED] Raycast

Author
Message
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 15th Feb 2019 08:14
How would I detect a collision between object 1 and object two. They are both spheres.

The author of this post has marked a post as an answer.

Go to answer

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 15th Feb 2019 08:20
This post has been marked by the post author as the answer.
returns 1 if there is a collision between the two objects
fubar
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 15th Feb 2019 08:24
if you're using 3D physics you could also use GetObject3DPhysicsFirstContact()
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 15th Feb 2019 09:41 Edited at: 15th Feb 2019 09:42
If its just 2 spheres then its a really simple case where you can work out the distance the spheres are apart from each other and see if it is less then the combination of radius's added together.


EDIT: please note I compare the square of each number as pow(a,2) is quicker than using sqrt()

Obviously, for more complex shapes then doing an object ray cast or using physics is a better way to go.

Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 15th Feb 2019 11:52
Hi thanks for the tips . I'll try and decipher the code and get it to work.
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 17th Feb 2019 09:07
Hi fubar I copied and pasted that code into my program. What do I need to type to get it to return a 0 or 1 . something like if collision = 1 then do something.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 17th Feb 2019 09:29
just pass the two object ids
if checkcollision(obect1id,obejct2id) =1 then do something
fubar
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 18th Feb 2019 09:18
Thanks very much fubar for your help I've now got it all working . Thanks for all the other replies also.

Login to post a reply

Server time is: 2024-11-23 05:05:20
Your offset time is: 2024-11-23 05:05:20