Question by
armandas2005 · Apr 16, 2021 at 01:05 PM ·
enemy
No Gravity?
i made this enemy script but my enemy starts flyng when i jump and it goes through walls (it has a Rigidbody and a boxcollider)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class AI_Walking : MonoBehaviour
{
public LayerMask player;
public Transform playerTransform;
public NavMeshAgent agent;
public float movementspeed = 3f;
public float sightRange;
public bool isInRange = false;
private void Awake()
{
agent = GetComponent<NavMeshAgent>();
}
private void Update()
{
isInRange = Physics.CheckSphere(transform.position, sightRange, player);
if(isInRange == true)
{
Attack();
}
if (isInRange == true)
{
transform.position += transform.forward * movementspeed * Time.deltaTime;
}
}
void Attack()
{
transform.LookAt(playerTransform.position);
}
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, sightRange);
}
}
Comment
Your answer
Follow this Question
Related Questions
Time delay enemy respawn 3 Answers
Why is my player dying when defeating an enemy? 1 Answer
My enemy ai won't stay on the ground help please 0 Answers
Increasing Enemy Speed 4 Answers