- Home /
To detect 'ground' for jumping, is physics.checksphere more efficient than raycast?
Historically I've always used a raycast to test if a character is grounded before allowing them to jump. Recently I met someone who suggested that physics.checksphere was a better method - and while I can definitely see some benefits (eg. catching 'late' jump inputs as characters approach edges), I was wondering if anybody could tell me which is more performant? Any other thoughts on this topic would be welcomed.
Answer by Namey5 · Jul 24, 2019 at 06:53 AM
In theory, checksphere is probably slightly more performant, but in practise they're both about as performant as each other. Although there may be a tiny bit of difference it probably isn't enough to worry about; especially considering you're only casting once when necessary.
Thank you Namey5, that's really useful! I don't suppose you know if there's any documentation on this?
There's not really any documentation on performance as such; and I really don't think there will be any noticeable difference in performance between the two. $$anonymous$$ost intersection tests are about the same as each other; with performance dependant on the number of colliders in the scene and their type (mesh colliders will always add a performance hit). If you really want some raw data, you could try both methods and then compare them with the profiler to see which is faster.
Nah, honestly, that sounds about right. I'm certainly not about to try to scrape back some cycles for a check-once-per-button-press physics check.
It's weird, though, I'd always thought Raycasts were the way to go with it, but I can see the point of checksphere.
If you'd like to format your comment as an answer, I'd be happy to mark it 'correct'.
Your answer
Follow this Question
Related Questions
BoxCollider vs. RaycastAll 1 Answer
Physics.Raycast (Cheapest Methods) 0 Answers
Understanding Raycast How Actually works in Unity [As Algorithm] 2 Answers
Performance of Physics.Raycast 3 Answers