Hi,
I am triying to make a third person camera view in my game. I’m new to unity and programming, so it’s quite difficult to understand and make what I want.
Here is my problem : I made a script (that works quite well) to make the camera follow and rotate behind my character, but I would like to restrain te camera movement into a specific area.
Another problem is that I made this script to work with a joystick, that’s why I can’t manage with mouse scripts.
I’d like someone to help me finish this script. Thanks in advance.
Here is the script :
function Start () {
}
var speed = 10.0f;
function Update()
{
var movement = Vector3.zero;
movement.y = Input.GetAxis("RightV");
movement.x = Input.GetAxis("RightH");
transform.Translate(movement * speed * Global.deltaTime, Space.Self);
return;
}
But I still have some problems. actually, the script worls as expected, only when the character is walking. When he’s idle, the camera gets too close to him and start spinning in some wierd way. I can figure out that the missing “space.self” could be the cause of this, but I can’t manage to fix it.
The whole code is there. The one in the first post rotates around the character when the right stick is used. No problem. But with the code Slev gave me, the camera is actually restrained as I want it to, but it sticks to the character and spins all alone.
If the script posted by slev is causing problems when you arent moving then you could cheat a little and disable it when you arent moving. if((Input.GetAxis("RightV") != 0 )(Input.GetAxis("RightH") !=0)) {do slevs code here}. This should be a cheap eficient and working quickfix. I dont really know where the problem came from because im replying from my phone but if i were to guess it was from the fact that axis when not moving have the value 0 wich could end up with tranform.localposition becoming 0.