- Home /
Camera Smooth Follow
Hi I have a problem with camera follow script. My scene is a "room". It's 3d iOs side Scroller. My character is starting to walk a long the room, but when I'am using camera follow script from Standard Assets user can see what is out side to room. I need camera to start follow when character is in the middle of iPhone screen and then when the room end's stop follow. What I should use? I was playing with offset but I need two different offsets. One from the beginning and another when room is going to the end. So maybe I need two collider's and when character trigger collider camera starts or stops follow him. How to make this follow but only in specific borders. I 'don't want to show what is outside the room.
Answer by zyzyx · Sep 10, 2012 at 03:48 PM
You can use Mathf.Clamp to clamp the position of your camera. Say you want to move your camera from -100 to 100 on the x-axis the code could look something like this (c#, not testet):
void Update()
{
Vector3 vec3 = transform.position;
vec3.x = Mathf.Clamp(vec3.x, -100, 100);
transform.position = vec3;
}
Answer by Anusha · Sep 07, 2012 at 11:21 AM
decrease the clipping planes in camera... decrease the 'Far' value until your camera shows only your room
Hi Anusha and thank you for trying help. :) I can not decrease the Far value because I don't want to show whole room. It's long room and it's a side scrolling game. User discover whole room during , character walk.
did you tried changing the normalised view port Rect values?
Yes I was playing with this but I guess It's not what I want. I need to show left side of the room, character is on the left side of iPhone screen. Character is start walking when he is in the middle of the iPhone screen camera starts to follow him. When room ends camera stop following him and character is going to the left side of the screen.
in unity camera script there is a mouse-orbit script.. in it the camera rotates according to the mouse drag.... there is a function called ClampAngle() used in it which restricts the rotation.... i think you could modify it to restrict the movement too.....
static float ClampAngle(float angle, float $$anonymous$$, float max) { if (angle < -360) { angle += 360; } if (angle > 360) { angle -= 360; } return $$anonymous$$athf.Clamp(angle, $$anonymous$$, max); }
HI Once more thank you Anusha. I attached a png to show what I need. I don't need to touch any angle's
Your answer
Follow this Question
Related Questions
Camera follow smoothness problem 1 Answer
Smooth Follow Problem 1 Answer
Why does the camera smoothly follow in one direction but not the other? 0 Answers
[Closed] SmoothFollow trouble 0 Answers