- Home /
switch character
,Hi guys . I have two characters in the game I want to change between them with the press of a button while the game is running. The camera also goes to the other player, while the first player follows the second player. I know that the question is a little bit complicated, but I need an answer, thank you all.
Answer by ray2yar · Jul 04, 2020 at 11:36 PM
Create a camera script that switches the camera focus... something like this:
public Transform[] targets;
int which = 0;
void Start()
{
which = 0;
}
void Update()
{
transform.position = targets[which].position;
if ()
{
which++;
if (which == 2) which = 0;
}
}
Of course you should add offsets and lerping... but that is the basic idea. As for controlling.... the characters... I would add a child gameobject slightly behind each player to about where you want the other character to follow. I would then build two separate "motor" scripts on the characters. On one would be player controls and on the other would be AI navigation controls. When the user switches players disable one and enable the other. For the AI - navmesh agent, set the target to the child object of the other character.
Your answer
Follow this Question
Related Questions
changing player (getting in vehicles) 3 Answers
Switching cameras (JavaScript) 0 Answers
Multiple Camera Switching 1 Answer
How can I change the character beign controled and the camera with a button? 1 Answer
how to position the camera? pls help. 0 Answers