- Home /
Lock target and orbit it
Hello community,
I have a controller script which is working fine. But now I want to add a feature to lock an enemy. While the enemy is locked the camera and character should always focus the target and when I move left/right, I want to orbit this target. (Like in Dark Souls/Demons Souls)
Any idea how I can archive that?
Thanks
Answer by Zodiarc · May 26, 2014 at 12:21 PM
I acheved something similar with a few lines of code. I don´t have the code right now, so I can´t look it up but i can give you the basic idea and edit the answer when I will be able to look it up.
The basic idea is: - You have a target, you want to lock on. You will need its position. - There is a Transform.LookAt function. You pass it the target´s position. - Next step is moving sideways. Transform.Translate(Vector3.right speed Time.deltaTime * ControllerAxisValue) should do it.
The outcome should be like this: - The character will be rotated towards the target - The character moves sideways. - In the next frame the character will be rotated towards the target again.
All this added together should result in an lock on with orbiting the target.
Note: This will only work properly if the player controls the orbiting character.
All 3 answers tell the same solution. But yours is the most detailed one. So I give you the correct answer. Thanks
Answer by Xephex · May 26, 2014 at 12:29 PM
You could try using the Transform.LookAt and set the enemy as your target. Like this
var enemy : Transform;
function Update() {
transform.LookAt(enemy);
}
Answer by Kaz_Yamof · May 26, 2014 at 12:25 PM
Try Transform.LookAt to look to your target. Then use transform.RotateAround and pass the axis to rotate, the point pivot to rotate and the angle.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
OnMouseDown on what? Camera Movement Help. 1 Answer
3rd person camera/movement 2 Answers
Advanced Orbit Camera Around Target 1 Answer
Orbit camer while paused? 1 Answer