Camera modes!

Desperate times call for desperate measures, I guess. For the camera to follow the player around, I had modified the SmoothFollow JavaScript code to fit my needs, which also exposed me to the wonderful that is the Lerp function. However, a game just can’t have one camera view, that would just be boring, since visuals and audio make up a huge part of the gaming experience.

Yesterday I had a conversation with a6yog to discuss the preview build. Apparently what a6yog meant by “bird’s eye view” was something much different than what I thought (and much cooler). He explained that, like in the bottom left corner of this picture, the camera would be able to rotate 360 degrees, so players travelling distances can enjoy the view while they move. Cool.

The idea is simple enough. Have the camera look outwards while rotating around using alt, and above the zoid. The camera starts at the back.

Of course, that meant that the original script was useless, except for the normal view, so I had to separate the scripts. I followed the model for weapons and movements – create a new Camera_Handle script which would handle changes to the camera state, and a host of other scripts that will do the meat of the positioning, since their states will be different.

The Follow_Mechscript was based on the original JS to BOO port, and the other, which I named as Bird_Mech. I messed around trying to make the camera rotate around the zoid, but there was the problem of making the entire process look smoother, i.e. using Lerp, or something similar.

In the end I used Vector3.Lerp and Quartenion.Lerp in Follow_Mech to shorten the entire script logic to 2 lines. One to shift the camera to the position behind the player, a simple

self.transform.localPosition=Vector3.Lerp(self.transform.localPosition, position , 0.1)

I’m using local position since I had the main cam become a child for easiness, but you can also just use world positions, just remember to minus them out.

The other line deals with shifting the angle towards the player. Since the camera should face the same way as the player, i.e. in front, and since the camera should be behind the player, I changed all that to:

self.transform.rotation=Quaternion.Lerp(self.transform.rotation, self.transform.root.rotation, rotationDamping*Time.deltaTime)

I could have added a LookAt(), but I guess there was not a need.

For Bird_Mech, I flipped it over with a simple

self.transform.localEulerAngles.y+=180 

which will reset when the in other modes.

For the rotation, I took the code from Motion_Mech for turning the zoid to :

self.transform.RotateAround(self.transform.root.position, Vector3.up, (rotationDamping * Time.deltaTime))

And voila! I have the look out 360 degrees code done, with a shortening of the original camera follow code. :P

By the way, we have additions to our team, Clown Baby will be taking care of some animations as an animator, while Nathan(Baws) will take care of the GUI. :D

 
1
Kudos
 
1
Kudos

Now read this

(first (look Hoplon.io))

Writing web applications can be a chore. With all the languages (minimum of HTML/CSS/JS) you need to learn just to write a single web page, with a little PHP thrown into the mix when you need to do server side computation, the simple... Continue →