- Home /
Can someone help me move my camera up a bit?
Hi there.
I have a Main Camera that looks for a target (the Player) prefab and will follow that around, having the target centered to the camera.
I need it to be liftet in the y-axis a little bit. Where in the code am I supposed to make a change and what change?
GameCamera.cs
using UnityEngine;
using System.Collections;
public class GameCamera : MonoBehaviour {
public Transform target;
public float trackSpeed = 10;
public void SetTarget (Transform t)
{
target = t;
//transform.position = new Vector3(t.position.x,t.position.y,transform.position.z);
}
void LateUpdate()
{
if (target)
{
float x = IncrementTowards(transform.position.x, target.position.x, trackSpeed);
float y = IncrementTowards(transform.position.y, target.position.y, trackSpeed);
transform.position = new Vector3(x,y, transform.position.z);
}
}
private float IncrementTowards(float n, float target, float a) {
if (n == target) {
return n;
}
else {
float dir = Mathf.Sign(target - n); // must n be increased or decreased to get closer to target
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign(target-n))? n: target; // if n has now passed target then return target, otherwise return n
}
}
}
Thanks!
Answer by Jeff-Kesselman · Jun 26, 2014 at 03:52 PM
Change where transform.position gets set to add something to your Y coordinate.
No, I won't write it for you. You will learn more if you figure it out for yourself.
Thank you for not writing it, specially when it was such a simple thing! I added it after target.position.y, simple as that. I just didn't know where or what to do :)
Your answer
Follow this Question
Related Questions
How can camera smoothly follow a jerky game object? (bouncing up and down) 1 Answer
How can i make the camera look up and down through keyboard keys? 2 Answers
How to make camera focus on a game Object in play mode? 1 Answer
Having Trouble animating camera at start of game 0 Answers
How to convert a camera controller code to the "new" input system? 0 Answers