unity3d人工智能编程精粹源码
Ⅰ Unity3D人工智能AI角色如何实现自主移动和行为操控
如果脚本逻辑都是正确的确实有可能是因为组件的问题。
但是目前这种情况很难看出来什么具体的内容,不知道你的逻辑都是怎么实现的?
如果方便的话可以看一看代码吗,或许可以看到更多的东西。
Ⅱ unity3d人工智能编程精粹 用什么语言
C# 不过用其他的也能实现 语言都差不多 看你什么用的顺手
Ⅲ unity3d ai是做什么的
Unity3d人工智能确定性AI算法。
核心代码:
using UnityEngine;
using System.Collections;
public class PlayObject : MonoBehaviour
{
[HideInInspector]
public float moveVx;//x方向的分速度
[HideInInspector]
public float moveVy;//y方向的分速度
/// <summary>
/// 2维坐标(x,y)
/// </summary>
public Vector2 Position
{
get
{
return new Vector2(this.transform.position.x, this.transform.position.y);
}
}
private Vector2 _vHeading;
/// <summary>
/// //设置导弹的前进方向的归一化向量m_vHeading
/// </summary>
public Vector2 vHeading
{
get
{
float length = Mathf.Sqrt(moveVx * moveVx + moveVy * moveVy);
if (length != 0)
{
_vHeading.x = moveVx / length;
_vHeading.y = moveVy / length;
}
return _vHeading;
}
}
private Vector2 _vSide;
/// <summary>
/// 前进方向的垂直向量
/// </summary>
public Vector2 vSide
{
get
{
_vSide.x = -vHeading.y;
_vSide.y = vHeading.x;
return _vSide;
}
}
/// <summary>
/// 速度向量
/// </summary>
public Vector2 Velocity
{
get
{
return new Vector2(moveVx, moveVy);
}
}
/// <summary>
/// 速度标量
/// </summary>
public float Speed
{
get
{
return Mathf.Sqrt(moveVx * moveVx + moveVy * moveVy);
}
}
public float MaxSpeedRate;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
/// <summary>
/// 移动物体
/// </summary>
/// <param name="speedRate">移动的速度率,一般为1</param>
/// <param name="isLookAtVelocityVector">是否要这是速度矢量与物体的朝向一致</param>
public void Move(float speedRate, bool isLookAtVelocityVector)
{
this.transform.position += new Vector3(moveVx * Time.deltaTime, moveVy * Time.deltaTime, 0) * speedRate;
// Debug.Log("x:" + m_postion.x + "y:" + m_postion.y);
//调整导弹的朝向是的它和速度矢量合成方向一样
if (isLookAtVelocityVector)
{
LookAtVelocityVector();
}
}
/// <summary>
/// 使得物体始终朝向矢量速度的方向
/// </summary>
void LookAtVelocityVector()
{
float zAngles = Mathf.Atan(moveVx / moveVy) * (-180 / Mathf.PI);
if (moveVy == 0)
{
zAngles = moveVx > 0 ? -90 : 90;
//跟以往的计算角度不同的是,这里加了moveVx==0的独立判断,这样可以在不控制的时候保持原状态
if (moveVx == 0)
{
zAngles = this.transform.rotation.eulerAngles.z;
}
}
if (moveVy < 0)
{
zAngles = zAngles - 180;
}
Vector3 tempAngles = new Vector3(0, 0, zAngles);
Quaternion tempQua = this.transform.rotation;
tempQua.eulerAngles = tempAngles;
this.transform.rotation = tempQua;
}
}
Ⅳ unity3d ai是做什么的
Unity3d人工智能确定性AI算法。
核心代码:
using
UnityEngine;
using
System.Collections;
public
class
PlayObject
:
MonoBehaviour
{
[HideInInspector]
public
float
moveVx;//x方向的分速度
[HideInInspector]
public
float
moveVy;//y方向的分速度
///
<summary>
///
2维坐标(x,y)
///
</summary>
public
Vector2
Position
{
get
{
return
new
Vector2(this.transform.position.x,
this.transform.position.y);
}
}
private
Vector2
_vHeading;
///
<summary>
///
//设置导弹的前进方向的归一化向量m_vHeading
///
</summary>
public
Vector2
vHeading
{
get
{
float
length
=
Mathf.Sqrt(moveVx
*
moveVx
+
moveVy
*
moveVy);
if
(length
!=
0)
{
_vHeading.x
=
moveVx
/
length;
_vHeading.y
=
moveVy
/
length;
}
return
_vHeading;
}
}
private
Vector2
_vSide;
///
<summary>
///
前进方向的垂直向量
///
</summary>
public
Vector2
vSide
{
get
{
_vSide.x
=
-vHeading.y;
_vSide.y
=
vHeading.x;
return
_vSide;
}
}
///
<summary>
///
速度向量
///
</summary>
public
Vector2
Velocity
{
get
{
return
new
Vector2(moveVx,
moveVy);
}
}
///
<summary>
///
速度标量
///
</summary>
public
float
Speed
{
get
{
return
Mathf.Sqrt(moveVx
*
moveVx
+
moveVy
*
moveVy);
}
}
public
float
MaxSpeedRate;
//
Use
this
for
initialization
void
Start()
{
}
//
Update
is
called
once
per
frame
void
Update()
{
}
///
<summary>
///
移动物体
///
</summary>
///
<param
name="speedRate">移动的速度率,一般为1</param>
///
<param
name="isLookAtVelocityVector">是否要这是速度矢量与物体的朝向一致</param>
public
void
Move(float
speedRate,
bool
isLookAtVelocityVector)
{
this.transform.position
+=
new
Vector3(moveVx
*
Time.deltaTime,
moveVy
*
Time.deltaTime,
0)
*
speedRate;
//
Debug.Log("x:"
+
m_postion.x
+
"y:"
+
m_postion.y);
//调整导弹的朝向是的它和速度矢量合成方向一样
if
(isLookAtVelocityVector)
{
LookAtVelocityVector();
}
}
///
<summary>
///
使得物体始终朝向矢量速度的方向
///
</summary>
void
LookAtVelocityVector()
{
float
zAngles
=
Mathf.Atan(moveVx
/
moveVy)
*
(-180
/
Mathf.PI);
if
(moveVy
==
0)
{
zAngles
=
moveVx
>
0
?
-90
:
90;
//跟以往的计算角度不同的是,这里加了moveVx==0的独立判断,这样可以在不控制的时候保持原状态
if
(moveVx
==
0)
{
zAngles
=
this.transform.rotation.eulerAngles.z;
}
}
if
(moveVy
<
0)
{
zAngles
=
zAngles
-
180;
}
Vector3
tempAngles
=
new
Vector3(0,
0,
zAngles);
Quaternion
tempQua
=
this.transform.rotation;
tempQua.eulerAngles
=
tempAngles;
this.transform.rotation
=
tempQua;
}
}