UNITY3D: Change Player Control to Target Model (FPS)

I am developing a small game prototype in Unity 3.5.5f, in which a player controls a small mind controlling a stranger. The player should be able to take control of the target human NPC by switching the entire camera and controls to the person in question.

NB All my code is still in C #.

I have two ideas on how to move forward, which is more possible? (I'm glad to hear alternative ideas)

  • Each person at the level has a deactivated FPS script controller (and related scripts). These scripts are activated during control (disabling the scripts of strangers for the duration).
  • Disconnect the current scripts from the alien and attach them to the target person.

Pros and cons, as far as I think:

  • It can have separate scripts for alien / human control (i.e. it is not necessary to use states for input - for example, it can shoot from a gun while a person is in it, and not in close combat, like an alien on LMB). This method is very classy.
  • This method is clean, but the code file for the player will be much larger, since I cannot easily separate the input code.

EDIT: A friend pointed out, yes, the NPC has its own scripts that will need to be disabled.

+6
source share
1 answer

It is quite simple in concept. Itโ€™s just that the NPC is like a playerโ€™s class, because it takes control when something is true.

For instance:

class NPC { static bool isBeingControlled = false; public void OnUpdate() { if (isBeingControlled) { //set camera position to NPC position (make sure you're using NPC as an instantiated class) //accept key input WASD or whatever you are using and move NPC according to input. } } 

}

You will need to create an NPC instance for each NPC that you have in your game.

+2
source

Source: https://habr.com/ru/post/927155/


All Articles