Jump to content

Quite complicated collision detection


pstrejczek
 Share

Recommended Posts

So .. I'm working on this little orbiting game and I have a problem with collision detection.

I have some sprites within the container. The container is rotating (so the sprites are also rotating). One of the sprites is an Arc.

What I want to do is to detect a collision of my player sprite with that arc. Any ideas how to achieve that?

Link to comment
Share on other sites

The built in physics engine has support for collision detection via circles as per:

https://www.panda2.io/examples#physics-Circle

So if you had your player sprite using a physics shape as well you could detect a collision between that and the circle.  After that you could qualify it further to the arc by using a known state.  So say your arc is 45 degrees and always starts at a given angle you'll know if its collided by checking its current angle vs it starting one when then circles collide.

Does that kind of make sense?

Link to comment
Share on other sites

That's what I have actually done - but without the physics engine. I'm still having some problems with the angles. I don't know if this has something to do with the container rotation taking place in update function in a different class than the one I'm doing collision checks. It kinda works - but sometimes doesn't :)

What I do is I check angles for the arc endpoints and then the angle of a vector from player position to the container center. Sometimes it looks like it hits out of the arc, but when I check values which are console.logged I can see it is not.

 I'm still looking for maybe a better solution

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...