- Home /
Character Runs Off Camera
Hello Unity3D i have a problem with my camera.The problem is my characters camera is auto targeting an enemy and whenever my character runs too far I can still see the enemy but i can't see the character that i have attached the camera to.What i want is no matter how far i go the camera still shows my character and the enemy.If anyone knows how i can do this.Can you please tell me how?
var target : Transform;
var moveSpeed = 20;
var rotationSpeed = 5;
var myTransform : Transform;
function Awake() {
myTransform = transform;
}
function Start() {
target = GameObject.FindWithTag("Eye").transform;
}
function Update () {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}
Wouldn't it be easier to set the transform in the inspector then trying to find a tag? And is your enemy tagged the same as your player?
Well it finds the enemy automatically when the battle begins.So i thought this way was better no my enemy tag and my characters tags are totally different
So it changes target to the enemy from the player when it spots an enemy. Should probably enable a battle camera ins$$anonymous$$d that has a higher view point and a bounding box that zooms the camera in and out when combat starts.
Answer by rantor88 · Jan 04, 2015 at 04:28 AM
When using a script to have a camera follow an object, whether in first person or third, its always best to use LateUpdate
rather than Update
. LateUpdate
occurs after update, and is best for tracking movement. I dont know if this will stop the character from falling off the screen, but it might make a difference in camera lag.
Hmmm...Intresting. What i was going to do was use the Var :ClampToScreen In order to make it that the character doesnt run off the camera.But alot of people tried and it didn't work for them.But ill try the LateUpdate ins$$anonymous$$d.Thank You Very $$anonymous$$uch!
Answer by makegoalken · Mar 04, 2020 at 08:09 AM
Your feedback helps me a lot, A very meaningful event, I hope everything will go well enable flash in chrome
Your answer
Follow this Question
Related Questions
Camera animation into a scene –most efficient way? 2 Answers
AI navigating all 6 sides of a cube 0 Answers
Slightly Scrolling Camera 1 Answer
Smooth Follow Rotation 3 Answers