- Home /
This question was
closed Dec 07, 2020 at 08:39 AM by
swastika_pallai for the following reason:
problem solved.
Question by
swastika_pallai · Dec 06, 2020 at 08:52 AM ·
unity 5rigidbody
my enemy passes through the walls in unity ?
hello!! i am facing a problem that my enemy can pass through rocks and all the things in the game... i am currently using transform.Translate
and transform.Rotate
in my script. And i also know that transform.Translate
avoids all the physics. To do this, i need to use Physics to move my character. However, i am very confused which one to use and how to use (coz , i am new to unity). so if anybody can help me, tell me what i should use.
here is the code i am using for enemy_movement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemy_movement : MonoBehaviour
{
public GameObject player;
Animator anim;
Rigidbody rb;
public float speed = 1.0f;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Vector3.Distance(transform.position, player.transform.position) < 25.0f)
{
anim.SetTrigger("isWalking");
//transform.LookAt(player.transform);
Quaternion targetRotation = Quaternion.LookRotation(player.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 1 * Time.deltaTime);
transform.position += transform.forward * 1f * Time.deltaTime;
}
}
}
Comment