博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UNITY 移动到指定位置的写法
阅读量:4081 次
发布时间:2019-05-25

本文共 1019 字,大约阅读时间需要 3 分钟。

//move towards a target at a set speed.private void MoveTowardsTarget() {    //the speed, in units per second, we want to move towards the target    float speed = 1;    //move towards the center of the world (or where ever you like)    Vector3 targetPosition = new Vector3(0,0,0);    Vector3 currentPosition = this.transform.position;    //first, check to see if we're close enough to the target    if(Vector3.Distance(currentPosition, targetPosition) > .1f) {         Vector3 directionOfTravel = targetPosition - currentPosition;        //now normalize the direction, since we only want the direction information        directionOfTravel.Normalize();        //scale the movement on each axis by the directionOfTravel vector components        this.transform.Translate(            (directionOfTravel.x * speed * Time.deltaTime),            (directionOfTravel.y * speed * Time.deltaTime),            (directionOfTravel.z * speed * Time.deltaTime),            Space.World);    }}

 

posted on 2016-12-07 19:54 阅读(...) 评论(...)

转载地址:http://rvvni.baihongyu.com/

你可能感兴趣的文章
链接点--数据结构和算法
查看>>
servlet中请求转发(forword)与重定向(sendredirect)的区别
查看>>
Spring4的IoC和DI的区别
查看>>
springcloud 的eureka服务注册demo
查看>>
eureka-client.properties文件配置
查看>>
MODULE_DEVICE_TABLE的理解
查看>>
platform_device与platform_driver
查看>>
platform_driver平台驱动注册和注销过程(下)
查看>>
.net强制退出主窗口的方法——Application.Exit()方法和Environment.Exit(0)方法
查看>>
c# 如何调用win8自带的屏幕键盘(非osk.exe)
查看>>
build/envsetup.sh 简介
查看>>
Android framework中修改或者添加资源无变化或编译不通过问题详解
查看>>
linux怎么切换到root里面?
查看>>
linux串口操作及设置详解
查看>>
安装alien,DEB与RPM互换
查看>>
编译Android4.0源码时常见错误及解决办法
查看>>
Android 源码编译make的错误处理
查看>>
linux环境下C语言中sleep的问题
查看>>
ubuntu 12.04 安装 GMA3650驱动
查看>>
新版本的linux如何生成xorg.conf
查看>>