Raycasting Struggles

For this next project, I’ve decided to implement a camera in a similar spirit to that of MOBAs or RTSs. This functionality would be to have a camera that moves independently of all things in the world, but can be locked to a specific object when required. This was a multistep process. First I needed to have a camera that could move with the key, simple task and was easily implemented. Then I needed to have it mount to something when needed. So I needed something to mount it to. I decided to go right into having the player movement as well, to save my time later on in development. So, I needed to be able to have a player move to a point that I clicked on within the screen.

This was not so simple.

I decided to look back at what I’ve done in the past and how I’ve gotten raycasting to work before. It turns out that my immediate belief that it would be too hard was an overreaction, because after generating a raycast at the point the player mouse is, checking if the player has clicked, and determining if the ray cast hit something, (all things I’ve done before) All I had to do was take the raycasthit.point value and feed it to a navmesh agent. So in reality, the only part I hadn’t done before was a single line, that was very specific to this task. Marvelous.


Now I had the player moving where I wanted him to, I needed to be able to lock the camera to it when necessary. So when is it necessary? I decided this was when the player pressed shift, but what was more interesting is when to stop following. The camera feels much more natural when you can move it away whenever you wish, with the movement keys. I used a bool that would switch between on and off when the camera locks. Every time the player presses any of the movement keys or shift, the camera lock changes accordingly.
I’d like to be able to get the camera to move with both a minimap and with the cursor by moving it to the edge of the screen. This thread details some ways that I could implement some of these camera systems at a later date. But for now, the camera work, and the player moves. Thats a win.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s