unity AI寻路

本文介绍了如何在Unity3D中利用Physic.RayCast实现AI敌人避开障碍物寻找目标的方法。通过在左右两侧投射射线检测障碍物,并根据检测结果调整AI的旋转和移动,以实现智能寻路。代码示例展示了具体的实现细节,包括射线检测范围、速度和旋转速度的设置。
摘要由CSDN通过智能技术生成

最近在在学习AI寻路中,找到了一些比较实用的干货,就是用Physic.RayCast 让敌人AI绕过障碍物找到玩家。
看到了别人的总结,所以分享一下,Physic.RayCast是一种能解决AI绕过障碍物的方法,但并不是一个完美的解决方法,同时里面一些参数需要根据游戏场景稍微进行调整。代码来源转自:http://www.theappguruz.com/blog/unity-3d-enemy-obstacle-awarness-ai-code-sample
代码:
Enemy AI
using UnityEngine;
using System.Collections;

public class EnemyAI: MonoBehaviour {
// Fix a range how early u want your enemy detect the obstacle.
private int range;
private float speed;
private bool isThereAnyThing = false;

// Specify the target for the enemy.
public GameObject target;
private float rotationSpeed;
private RaycastHit hit;
// Use this for initialization
void Start() {
range = 80;
speed = 10 f;
rotationSpeed = 15 f;
}

// Update is called once per frame
void Update() {
//Look At Somthly Towards

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值