Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rshapes]Circle line collision function #4018

Merged
merged 16 commits into from
May 30, 2024

Conversation

kai-z99
Copy link
Contributor

@kai-z99 kai-z99 commented May 30, 2024

Added a function to check collision between a line defined by p1, p2 and a circle defined by its position and radius. This code is tested in https://github.com/kai-z99/raylib/blob/circleLineDev/examples/shapes/shapes_collision_area.c

This function is intended to a standalone collision detection function as well as possibly a helper function for a polygon-circle collision function.

The algorithm is based on https://www.jeffreythompson.org/collision-detection/line-circle.php

It is also similar to this one: #4000 (which is closed)

Screenshot 2024-05-29 213049
Screenshot 2024-05-29 213032
Screenshot 2024-05-29 213011

@kai-z99 kai-z99 changed the title Circle line collision function [rshapes]Circle line collision function May 30, 2024
@raysan5 raysan5 merged commit 606cc1d into raysan5:master May 30, 2024
@raysan5
Copy link
Owner

raysan5 commented May 30, 2024

@kai-z99 Thanks for the addition! I try to minimize this kind of functions on raylib, they probably belong to a physics engine more than raylib but adding this one for convenience. Thanks!

@kai-z99
Copy link
Contributor Author

kai-z99 commented May 30, 2024

@raysan5 Thanks! I was planning to make a polygon to circle collision function, would that be appropriate? I've created a few games in raylib so far and I always felt it would be super handy as opposed to making a custom one for the game or introducing physics lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants