Facing the Camera: “Physics.Raycast” vs “Vector3.Dot” in Unity3D

I had a great time this week, having been given the opportunity to present a talk at IGDA – Ann Arbor in Ypsilanti, Michigan this month. I’ve been attending their meetups for over a year, and they consistently get a great turnout and great discussions. This time, group was a good size, the audience seemed interested, and I didn’t mumble as much as I tend to. Of course, the talk was about “3D Cel Animation.”

But with many developers and programmers in the room, they brought up some suggestions to optimize how I check which ‘perspective’ of a character should be shown at a given frame. A common suggestion was to use “dot product” at a low-level instead of relying on “Physics.Raycast.” Even years ago, this had been suggested to me. I had fears about its’ efficiency, but after a few one-on-one discussions, I agreed it might turn out to be more efficient, and it wouldn’t be hard to implement.

I felt like such a fool. For 5 years, I’ve preached the brilliance and simplicity of my design! Was an alternate solution so obvious, and really better?

So I gave it a try. And the results surprised me.

A visual comparing “RaycastAll,” “Raycast” and “Dot Product” as they relate to knowing what orientation a character is in.

Continue reading

An Alternate Method To Recognize When Objects Are Between Your Player and Game Camera

It’s almost 2018, I plan to write a status report of my game development status soon. In short, I think I spent most of my dev time in 2017 on trees, and am still doing so even today. At least I learned a lot… still feels frustrating though.

For some time, I’ve ignored an issue where objects are in between my game camera and the focus object (in my case, the player). My past games had sparse environments, so this was never really a problem. But my current game will be a bit more diverse than that. When thinking about how to resolve this, I realized there is a simple solution that, while not perfect, gives acceptable results.

There’s more than one way to skin a tree…

Continue reading