Hey guys…anybody know how to make a camera follow a game object like in a side scroller? The examples in the References make the camera rotate to look at a target, but I was looking for more of a translate in Y and Y only. Any ideas? Thanks!
Just position the camera at target.transform + Vector3D(0, distance, 0) in the LateUpdate and put that script onto your camera.
Is there a way to implement that into the script I’m already using?
var Target : Transform;
function LateUpdate () {
transform.LookAt (Target);
}
var Target : Transform;
function LateUpdate () {
transform.position = Target.position + Vector3d(0, distance, 0);
}
Sweet! Thanks guys…its working perfectly. I love these forums. Sorry for the noob questions :lol:
Hi guys,
This is exactly what i need. However im having issues as im a noob to unity. When i try to implement the script i get the following errors.
unknown identifier “vector3d”
unknown identifier “distance”
any help would be appreciated as my deadline for this project is looming :))
thanks
Can you paste the code? Also what language are you using?
var Target : Transform;
function LateUpdate () {
transform.position = Target.position + vector3d(0, distance, 0);
}
Thanks for your reply. Its no different to that above, blt3d seems to have had success with it, i was hoping it would work straight off for me too.
That’s the only code you have?
If you simply copied and pasted the code from this thread to use in your project, it won’t work.
The reason for this is that you have no “distance” variable defined. Distance means nothing to your code right now.
Also, vector3D needs to be capitalized since it is a type. Vector3D. At least, I’m assuming javascript is case sensitive.
Make sure in your code that distance has some meaning. Define it up near the top as a variable… like var distance = 5; Or whatever it is you want.
Marvellous, that worked a treat on one error. Still receiving an error on that VECTOR3D.
I’m sure you have realised by now that I am in my first week of looking at java, I have an idea how it works, but not how to work it if that makes sense. I appreciate your help!
Oh whoops sorry. It’s supposed to be Vector3, not Vector3D, my bad.
I didn’t catch your error before.
function LateUpdate () {
transform.position = Target.position + Vector3(0, distance, 0);
you sir are legend, IT WORKS. Thanks you very much!
I look forward to learning much more
Haha, that’s just syntax and proper language utilization(like not using unassigned variables). You’ll definitely need to learn that or you’re going to be in for a world of hurt.
yeah this is a strange brief for us. I study interactive media design with the focus on human computer interaction, not much scripting involved at all. This games module is slapped into it, didnt think it would be my thing but im quite enjoying it.
Gonna try and figure out how to angle the camera down a bit now I think.
Right i got the angle i needed by combining the standard look at script with the scroll script.
var Target : Transform;
var distance = 5;
function LateUpdate () {
transform.position = Target.position + Vector3(0, distance, -30);
transform.LookAt (Target);
}
And it works! This is fun, thanks again.
can anybody tell how to follow this camera for different object (means i have 4 4 character i can swap move then ???)
put this on a orthographic camera to just follow the y axis.
transform.position.y = player.transform.position.y;