When I add a rigidbody, it disables all my sounds in the game?
I had some AI that walked through objects in the scene, therefore I added rigidbodies to them and changed the script - that chases the player - accordingly. The AI now cannot walk through objects with colliders, however now my background music is not working and other sounds, such as, vehicle noise. However, my reload clicks are working.
Hi there, this isn't really enough to go on. Can you try to narrow down where the problem might be and post some code snippets?
Here is the script that controls the AI, I have used transform now ins$$anonymous$$d of rigidbodies because I needed my music to work, now they are walking through objects in the scene, any way to prevent this?
using UnityEngine;
using System.Collections;
using UnityEngine.AI;
public class ZombieHoardController : $$anonymous$$onoBehaviour
{
private Nav$$anonymous$$eshAgent nav$$anonymous$$eshAgent;
public Transform target;
private Animator myAnimator;
public bool chaseTarget = true;
public float stoppingDistance = 2.5f;
public float delayBetweenAttacks = 1.5f;
private float attackCooldown;
private float distanceFromTarget;
public int damage = 1;
private PlayerHealth playerHealth;
// Use this for initialization
void Start()
{
nav$$anonymous$$eshAgent = GetComponent<Nav$$anonymous$$eshAgent>();
myAnimator = GetComponent<Animator>();
nav$$anonymous$$eshAgent.stoppingDistance = stoppingDistance;
attackCooldown = Time.time;
playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerHealth>();
}
// Update is called once per frame
void Update()
{
if (Vector3.Distance(target.position, this.transform.position) < 15)
{
Vector3 direction = target.position - this.transform.position;
direction.y = 0;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f);
ChaseTarget();
}
else
{
myAnimator.SetBool("isIdle", true);
//Turn running off
myAnimator.SetBool("isChasing", false);
chaseTarget = false;
}
}
void ChaseTarget()
{
distanceFromTarget = Vector3.Distance(target.position, transform.position);
if (distanceFromTarget >= stoppingDistance)
{
chaseTarget = true;
}
else
{
chaseTarget = false;
Attack();
}
if (chaseTarget)
{
nav$$anonymous$$eshAgent.SetDestination(target.position);
myAnimator.SetBool("isChasing", true);
}
else
{
myAnimator.SetBool("isChasing", false);
}
}
void Attack()
{
if (Time.time > attackCooldown)
{
playerHealth.TakeDamage(damage);
myAnimator.SetTrigger("Attack");
attackCooldown = Time.time + delayBetweenAttacks;
}
}
}
$$anonymous$$anipulating the transform ignores physics, so that's where your clipping problem is. As for the music not working, at what point does it stop working? I'm seeing no audio manipulation in this class.
Your answer
![](https://koobas.hobune.stream/wayback/20220612121012im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
calculate what angle should the turret fire with a rigibody bullet [C#] 0 Answers
Question about NavMesh and Rigidbody 0 Answers
Issues Getting my GameObject to both Move Forward and Jump properly. 0 Answers
Question About NavMesh Agent and rotation 1 Answer
Problem of stuttering FPS Camera 1 Answer