随机移动尝试
Random movement attempt
我试图让我的熊在玩家不在它的范围内时随机行走。我想让它随机 select 它在 y 轴上的旋转,然后向前移动它,一段时间后再次随机切换旋转。
问题是我真的不知道如何给他分配随机轮换。
那么我该怎么做呢?
我终于成功了,这是工作代码:
var timeToChangeDirection : float = 60;
private var angle : Vector3;
var damping : float = 6.0;
var controller : CharacterController;
function Update()
{
distance = Vector3.Distance(target.position, transform.position);
if(distance > aggroRange)
{
moveSpeed = 1;
timeToChangeDirection -= 0.1;
if (timeToChangeDirection <= 0)
{
ChangeDirection();
}
controller.Move(transform.forward * Time.deltaTime);
animation["Run"].speed = 0.25;
animation.Play("Run");
}
function ChangeDirection()
{
angle = Vector3(transform.rotation.x, Random.Range(-359, 359), transform.rotation.y);
transform.Rotate(angle);
timeToChangeDirection = 60;
}
好的。毕竟我已经设法做到了。
如果有人感兴趣,这是代码:
var timeToChangeDirection : float = 60;
private var angle : Vector3;
var damping : float = 6.0;
var controller : CharacterController;
function Update()
{
distance = Vector3.Distance(target.position, transform.position);
if(distance > aggroRange)
{
moveSpeed = 1;
timeToChangeDirection -= 0.1;
if (timeToChangeDirection <= 0)
{
ChangeDirection();
}
controller.Move(transform.forward * Time.deltaTime);
animation["Run"].speed = 0.25;
animation.Play("Run");
}
function ChangeDirection()
{
angle = Vector3(transform.rotation.x, Random.Range(-359, 359), transform.rotation.y);
transform.Rotate(angle);
timeToChangeDirection = 60;
}
我试图让我的熊在玩家不在它的范围内时随机行走。我想让它随机 select 它在 y 轴上的旋转,然后向前移动它,一段时间后再次随机切换旋转。
问题是我真的不知道如何给他分配随机轮换。 那么我该怎么做呢?
我终于成功了,这是工作代码:
var timeToChangeDirection : float = 60;
private var angle : Vector3;
var damping : float = 6.0;
var controller : CharacterController;
function Update()
{
distance = Vector3.Distance(target.position, transform.position);
if(distance > aggroRange)
{
moveSpeed = 1;
timeToChangeDirection -= 0.1;
if (timeToChangeDirection <= 0)
{
ChangeDirection();
}
controller.Move(transform.forward * Time.deltaTime);
animation["Run"].speed = 0.25;
animation.Play("Run");
}
function ChangeDirection()
{
angle = Vector3(transform.rotation.x, Random.Range(-359, 359), transform.rotation.y);
transform.Rotate(angle);
timeToChangeDirection = 60;
}
好的。毕竟我已经设法做到了。 如果有人感兴趣,这是代码:
var timeToChangeDirection : float = 60;
private var angle : Vector3;
var damping : float = 6.0;
var controller : CharacterController;
function Update()
{
distance = Vector3.Distance(target.position, transform.position);
if(distance > aggroRange)
{
moveSpeed = 1;
timeToChangeDirection -= 0.1;
if (timeToChangeDirection <= 0)
{
ChangeDirection();
}
controller.Move(transform.forward * Time.deltaTime);
animation["Run"].speed = 0.25;
animation.Play("Run");
}
function ChangeDirection()
{
angle = Vector3(transform.rotation.x, Random.Range(-359, 359), transform.rotation.y);
transform.Rotate(angle);
timeToChangeDirection = 60;
}