Объект с которым надо взаимодействовать один?
но тут есть бескрайнее поле для оптимизации.
Ну и может ECS чем поможет.
Кубический тригер возможно поможет(как в марио)
void Update(){
BotMove();
}
float BotSpeed = 3f;
float JumpHeight = 7f;
float Gravity = 20f;
Vector3 MoveDirection = Vector3.zero;
GameObject BotObject;
Animator BotAnimator;
CharacterController BotController;
float InputGetAxisVertical{ get { return Input.GetAxis("Vertical"); }}
float InputGetAxisHorizontal{ get { return Input.GetAxis("Horizontal"); }}
void BotMove(){
BotAnimator.SetBool("Grounded", BotController.isGrounded);
MoveDirection = new Vector3(InputGetAxisHorizontal, 0.0f, InputGetAxisVertical) * BotSpeed;
if(BotController.isGrounded){
if(InputGetAxisVertical == 0f && InputGetAxisHorizontal == 0f){ BotSpeed = 0f; }
else{
if(Input.GetKey(KeyCode.LeftShift)){ BotSpeed = 6f; }else{ BotSpeed = 3f; }
Quaternion BotTargetAngle = Quaternion.LookRotation(MoveDirection);
BotObject.transform.rotation = Quaternion.Slerp(BotObject.transform.rotation, BotTargetAngle, 2f);
}
BotAnimator.SetBool("Jump", false);
BotAnimator.SetBool("FreeFall", false);
if(Input.GetButton("Jump")){
MoveDirection.y = JumpHeight;
BotAnimator.SetBool("Jump", true);
}
}else if(MoveDirection.y < - 5f){ BotAnimator.SetBool("FreeFall", true); }
MoveDirection.y -= Gravity * Time.deltaTime;
BotController.Move(MoveDirection * Time.deltaTime);
BotAnimator.SetFloat("Speed", BotSpeed);
BotAnimator.SetFloat("MotionSpeed", 1f);
}
Vector3 direction = new Vector3(InputGetAxisHorizontal, 0.0f, InputGetAxisVertical) * BotSpeed;
Quaternion rotGoal = Quaternion.LookRotation(direction);
PlayerObject.transform.rotation = Quaternion.Slerp(PlayerObject.transform.rotation, rotGoal, 2f);
private void OnCollisionEnter(Collision collision){ if(collision.gameObject.tag == "Ground"){ Grounded = true; }}
private void OnCollisionExit(Collision collision){ if(collision.gameObject.tag == "Ground"){ Grounded = false; }}
private void MoveCamera(){
PlayerModel.transform.Translate(0, 0, InputGetAxisVertical * Time.deltaTime);
PlayerModel.transform.Rotate(0, InputGetAxisHorizontal * Time.deltaTime, 0);
}
// на
private void MoveCamera(){
PlayerModel.transform.Translate(0, 0, InputGetAxisVertical * Time.deltaTime);
PlayerModel.transform.Translate(InputGetAxisHorizontal * Time.deltaTime, 0, 0);
}
private void AimCamera(){
if(Input.GetMouseButton(0)){
MoveHeadY -= InputGetAxisMouseY;
MoveHeadY = Mathf.Clamp(MoveHeadY, -40f, 40f);
MoveHeadX += InputGetAxisMouseX;
MoveHeadX = Mathf.Clamp(MoveHeadX, -75f, 75f);
PlayerHeadCharacterController.transform.localRotation = Quaternion.Euler(MoveHeadY, MoveHeadX, 0f);
}
}
// на
private void AimCamera(){
if(Input.GetMouseButton(0)){
MoveHeadY -= InputGetAxisMouseY;
MoveHeadY = Mathf.Clamp(MoveHeadY, -40f, 40f);
MoveHeadX += InputGetAxisMouseX;
PlayerModel.transform.Rotate(0, MoveHeadX * Time.deltaTime, 0);
PlayerHeadCharacterController.transform.localRotation = Quaternion.Euler(MoveHeadY, 0, 0f);
}
}