- Home /
Camera movement
Hi there, I would just like to move my camera in Y everytime I slide ( every time I press right click ) and put back my camera position at his original position Sorry for the question Im still a newbie...
From the little I could pickup from your explanation, I'm guessing you want the camera to move downwards when the player is sliding and then move back up to the original position afterwards - like in temple run for instance.. If that is what you are trying to do, then I'd perhaps suggest using an animation ins$$anonymous$$d of coding that camera movement. It is also possible through code but it's a lot harder/more work to get the movement to smooth properly, in my opinion. Just create an animation for the camera movement and then play it when the right mouse button is clicked :)
ok thx i will try this, perhaps i have no animation yet, my avatar is place holder and I have no idea how to animate the camera.
P.S. lol for the 1 hour post..... ;)
C# is fine too, you can call the animation easily with either language.. To create an animation you can go to your animation window (in the menu: Window -> Animation), but I'd recommend watching a tutorial first. Basic steps would be: create a camera animation, call the animation from your script
Answer by Seth-Bergman · May 01, 2012 at 03:51 PM
var originalPosition : Vector3;
function Update ()
{
if(Input.GetMouseButton(1))
transform.Translate(0,-moveSpeed,0);
else if (transform.position.y < originalPosition.y)
transform.Translate(0,moveSpeed,0);
}
this is the simplest way I can write this... Oh yeah, this script would be attached to the camera. If you want a smoother movement though, you would use a Lerp:
var originalHeight : float;
var minimumAllowableHeight : float;
var moveSpeed : float = 1;
function Update ()
{
if(Input.GetMouseButton(1))
{
//originalHeight = transform.position.y; // in case this changes
transform.position.y = Mathf.Lerp(transform.position.y,minimumAllowableHeight);
}
else if (transform.position.y < originalHeight)
transform.position.y = Mathf.Lerp(transform.position.y,originalHeight);
}
Your answer
Follow this Question
Related Questions
Place a object in front the camera in the coordinate 0 of Y axis 2 Answers
Trouble converting transform.position to C# 1 Answer
How to make Main Camera to not follow object on Y 3 Answers
Following a gameObject, unexpected problems? 1 Answer
Place object in front of me with given Translation Vector 0 Answers