- Home /
Camera position
This must have been asked a thousand times, as it's pretty basic. But I'm not able to grasp it. So I'm trying a seemingly simple control scheme here. The player uses a joypad, with the left analog stick the character moves forward/backward and sidesteps. The right analog stick is supposed to rotate the camera + character along the character's up direction, and moving the analog stick upwards rotates the camera along the right axis of the character. I've been trying to create a system that saves the direction of the camera and the distance to the player, but I can't make it seem to work. How would I best go about this?
Answer by Berenger · May 26, 2012 at 03:31 PM
Import the Character Controller package and take a look at the MouseLook script. You will need to adapt it a bit to replace the mouse input by the analog stick input, but otherwise it's seems similar.
Then, attach that script to the player and parent the camera to him.
Thanks! I've been looking at it and just one thing is foreign to me: at the top is a property called 'enum' and I'm not entirely sure what this does?
enum is, I'd say a Type, but anyway it associate a name to an int. It can be use to have more option than a boolean. Here is an example :
// Those two lines are identical, I wrote both to point out what's going on public enum AI$$anonymous$$ode{ Enemy = 0, Ally = 1, Neutral = 2 } //public enum AI$$anonymous$$ode{ Enemy, Ally, Neutral }
// This can be modified in the inspector // As you'll see the name, it's much easier to remember what does what. // $$anonymous$$eyCode is an enum, imagine if we had to remember that 46 is Escape etc. public AI$$anonymous$$ode mode; public void OnTriggerEnter(){ if( mode == AI$$anonymous$$ode.Enemy ) // Enemy stuff else if( mode == AI$$anonymous$$ode.Ally ) // Ally stuff else if( mode == AI$$anonymous$$ode.Neutral ) // Neutral stuff }
Your answer
Follow this Question
Related Questions
Move character in direction its facing 1 Answer
find a world-space coordinate from ScreenPointToRay(Input.mousePosition) raycast 2 Answers
Not shooting in desired direction 1 Answer
RTS camera help 1 Answer
Calculate vector3 from angle 2 Answers