Post by atrofeed on Oct 16, 2022 17:46:32 GMT
I am doing some bullet time stuff and I want the enemy AI to react slower during bullet time. I am manipulating the timescale of the scene to create the bullet time effect. Turning down the animatorSpeed on vAIMotor (which is inside vControlAIShooter component) is not enough, because the enemy AI still turns fast , only the animation gets slowed. During testing I found out that changing the values of rotationSpeed, walkSpeed, runningSpeed, printSpeed and crouchSpeed during runtime would suffice.
Only problem is that I cannot access these variables (I can access animatorSpeed, because it sits nicely in the vAIMotor class in vAIMotor.cs), because the class vMovementSpeed (which is also in vAIMotor.cs, but in a different class; two classes in the same script) does not derive from MonoBehavior, which means I cannot use a GetComponent. This means that code like something below to set the variables for each relevant AI components for each enemy does not work. I cannot let the class derive from MonoBehavior (i.e. public class vMovementSpeed : MonoBehaviour in script vAIMotor.cs around line 1300) , because Invector throws errors if I do.
Anyone got suggestions on how to set rotationSpeed, walkSpeed, runningSpeed, printSpeed and crouchSpeed in the AI Shooter Controller (vControlAIShooter --> vAIMotor) via code?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Invector.vCharacterController.AI;
using System.Collections.Generic;
using UnityEngine;
using Invector.vCharacterController.AI;
public class ChangeAnimationSpeedAI : MonoBehaviour
{
public GameObject[] gos;
public List<Component> componentsList;
public float newAnimationSpeed = 0.01f;
public float newrotationSpeed = 0.1f;
public float newwalkSpeed = 0.02f;
public float newrunningSpeed = 0.03f;
public float newsprintSpeed = 0.04f;
public float newcrouchSpeed = 0.02f;
public float newrotationSpeed = 0.1f;
public float newwalkSpeed = 0.02f;
public float newrunningSpeed = 0.03f;
public float newsprintSpeed = 0.04f;
public float newcrouchSpeed = 0.02f;
public void GrabAllEnemiesAIMovementSpeed()
{
gos = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject go in gos)
{
vAIMotor.vMovementSpeed[] aimotors = go.GetComponents<vAIMotor.vMovementSpeed>(); //the problem
foreach (vAIMotor.vMovementSpeed item in aimotors)
{
componentsList.Add(item);
}
}
Debug.Log("Done finding enemies and their aimotors");
}
{
gos = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject go in gos)
{
vAIMotor.vMovementSpeed[] aimotors = go.GetComponents<vAIMotor.vMovementSpeed>(); //the problem
foreach (vAIMotor.vMovementSpeed item in aimotors)
{
componentsList.Add(item);
}
}
Debug.Log("Done finding enemies and their aimotors");
}
public void ChangeMovementSpeeds()
{
foreach (vAIMotor.vMovementSpeed aimotorspeed in componentsList)
{
Debug.Log("Changed animation speed");
aimotorspeed.rotationSpeed = newrotationSpeed;
aimotorspeed.walkSpeed = newwalkSpeed;
aimotorspeed.runningSpeed = newrunningSpeed;
aimotorspeed.sprintSpeed = newsprintSpeed;
aimotorspeed.crouchSpeed = newcrouchSpeed;
Debug.Log(aimotorspeed.rotationSpeed);
Debug.Log(aimotorspeed.walkSpeed);
Debug.Log(aimotorspeed.runningSpeed);
Debug.Log(aimotorspeed.sprintSpeed);
Debug.Log(aimotorspeed.crouchSpeed);
}
{
foreach (vAIMotor.vMovementSpeed aimotorspeed in componentsList)
{
Debug.Log("Changed animation speed");
aimotorspeed.rotationSpeed = newrotationSpeed;
aimotorspeed.walkSpeed = newwalkSpeed;
aimotorspeed.runningSpeed = newrunningSpeed;
aimotorspeed.sprintSpeed = newsprintSpeed;
aimotorspeed.crouchSpeed = newcrouchSpeed;
Debug.Log(aimotorspeed.rotationSpeed);
Debug.Log(aimotorspeed.walkSpeed);
Debug.Log(aimotorspeed.runningSpeed);
Debug.Log(aimotorspeed.sprintSpeed);
Debug.Log(aimotorspeed.crouchSpeed);
}
}