Camera Collisions – SphereCast Update 13th Aug 2018

Development Update 13th August 2018

SphereCast all the way!

I enjoyed sharing my work on the character controller recently, so much so that I wanted to share another mini-tutorial with you about the game’s third person camera and the way it collides with obstacles in the world!

This update has been a long time coming, since the camera was in an acceptable state for a long time, it never felt like it was too urgent to fix just yet. That said, it had a pretty glaring issue with the way it was detecting collisions, using RayCasting. The camera would work 80~90% of the time quite well, but the rest of the time would shake and judder at its collision point. The main technique I used to fix this issue was switching to a thing called SphereCasting.

Now just what is RayCasting and SphereCasting? RayCasting involves drawing a line (a ray) from an origin point in a specified direction. Upon intersecting with a collider, it returns a RayCastHit with information about the point of contact with the other object. SphereCasting is similar, but where as RayCasting looks at one point, SphereCasting draws a sphere out from an origin point along a specified path direction.

It might be hard to understand (certainly hard to explain!), but I found a fantastic visualization posted on Reddit from an unfortunately deleted user. Check it out here:

So, how does this work in CyberThreat? In CyberThreat, the camera is set to orbit around a camera target object. A SphereCast of a set radius is drawn from the target to the camera, for a max distance that matches the camera’s resting distance. Any detected collisions are returned, and the distance to the collision point is used in updating the camera’s distance to the target.

A glimpse of it in action! So much smoother…

Why is this better than RayCasting? SphereCasting is able to “catch” more collision points within its radius than a Ray, which only looks at one point. This means little crevices or gaps aren’t an issue when detecting collisions anymore.

The red wire sphere represents the area to detect collisions around the camera. Collisions between the camera and the target are also caught along the SphereCast.

So the main collision detection looks something like this:

RaycastHit hit;

Vector3 start = TargetLookAt.transform.position;
Vector3 dir = this.transform.position - start;

Ray x = new Ray (start, dir);

Vector3 closestHitPoint =;

if (Physics.SphereCast(x, radius, out hit, distanceMax)) {
		pointOfContact = hit.point;

Something that tripped me up for a while is remembering to account for colliding with Triggers! The SphereCast will catch them too, so remember to check whatever the hit point is attached too to see if it’s a collider or trigger!

And that’s pretty much it for now! Hopefully if you’re stuck in a similar situation where RayCasting just won’t cut it, that this can help. There’s a lot more that can be done using SphereCasting than just camera collisions, I look forward to experimenting more with it!

If you haven’t already, make sure to like the CyberThreat Facebook page and follow on Twitter for more updates!



Also join the official Discord server!

Before I go, a sneak preview for a future update…

Battle Menu Wheel! Because UI can always be improved too!

Thanks for reading!


Anime Expo 2018 – Sponsorship

Anime Expo kicks off on July 5th, and I’m very excited to reveal that CyberThreat is sponsoring AnimeWorld’s booth this year!

CyberThreat joins other sponsors such as Yandere Simulator at their booth, be sure to check it out if you’re there! If you want to share your pictures of the booth and the CyberThreat logo on Facebook and Twitter, feel free to use the hashtag #CyberThreatAnimeExpo!

You can read more here:

Conor McKenna

New Website Launched

Welcome all to CyberThreat’s newly redesigned website! The game has undergone so many changes and improvements since it was last shown, so it was necessary to create a fresh new look for the game’s website to represent it. There is a lot more to come of course, thank you for your patience while the website is still being put together.

It’s an exciting time for CyberThreat, be sure to stick around and check things out soon as even more is revealed in greater detail!

Conor McKenna