Ⅰ 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;
}
}