当前位置: 首页 > news >正文

辽宁省交通建设投资集团网站/关于市场营销的100个问题

辽宁省交通建设投资集团网站,关于市场营销的100个问题,莱芜招聘信息最新招聘2022,网站开发各个文件文章目录 1、rb.MovePosition方法2、rb.velocity方法3、rb.AddForce 方法:接受一个向量参数,表示要施加的力的大小和方向。4、transform.Translate方法:接受一个向量参数,表示要移动的方向和距离。5、 Mathf.Lerp 函数可以平滑地将…

文章目录

  • 1、rb.MovePosition方法
  • 2、rb.velocity方法
  • 3、rb.AddForce 方法:接受一个向量参数,表示要施加的力的大小和方向。
  • 4、transform.Translate方法:接受一个向量参数,表示要移动的方向和距离。
  • 5、 Mathf.Lerp 函数可以平滑地将一个值从一个范围过渡到另一个范围。
  • 6、 Vector3.SmoothDamp 函数:接受四个参数:current:当前值;target:目标值;currentVelocity:当前速度,这个值会在函数中被修改以实现平滑过渡;smoothTime:平滑时间,表示从当前值到目标值所需的时间。
  • 7、MoveTowards 方法:接受三个参数:当前位置、目标位置和移动速度。
  • 8、Move 方法:接受一个向量参数,表示要移动的方向和距离。

1、rb.MovePosition方法

public class PlayerController : MonoBehaviour
{public float speed = 5.0f;public float smoothing = 0.1f;public float rotationSpeed = 5.0f;private Vector3 targetPosition;private Rigidbody rb;void Start(){rb = GetComponent<Rigidbody>();targetPosition = transform.position;}void FixedUpdate(){float h = Input.GetAxisRaw("Horizontal");float v = Input.GetAxisRaw("Vertical");Vector3 direction = new Vector3(h, 0, v).normalized;if (direction.magnitude >= 0.1f){targetPosition += direction * speed * Time.deltaTime;Vector3 smoothedPosition = Vector3.Lerp(transform.position, targetPosition, smoothing);// 计算玩家应该面对的方向Vector3 lookDirection = targetPosition - transform.position;Quaternion targetRotation = Quaternion.LookRotation(lookDirection);// 平滑地旋转玩家的朝向rb.MoveRotation(Quaternion.Lerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime));rb.MovePosition(smoothedPosition);}}
}

2、rb.velocity方法

public class PlayerController : MonoBehaviour
{public float speed = 5.0f;public float rotationSpeed = 5.0f;private Vector3 targetPosition;private Quaternion targetRotation;private Rigidbody rb;void Start(){rb = GetComponent<Rigidbody>();targetPosition = transform.position;targetRotation = transform.rotation;}void FixedUpdate(){float h = Input.GetAxisRaw("Horizontal");float v = Input.GetAxisRaw("Vertical");Vector3 direction = new Vector3(h, 0, v).normalized;if (direction.magnitude >= 0.1f){targetPosition += direction * speed * Time.deltaTime;Vector3 lookDirection = targetPosition - transform.position;targetRotation = Quaternion.LookRotation(lookDirection);rb.velocity = direction * speed;}else{rb.velocity = Vector3.zero;}rb.MoveRotation(Quaternion.Lerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime));}
}

3、rb.AddForce 方法:接受一个向量参数,表示要施加的力的大小和方向。

public class PlayerController : MonoBehaviour
{public float moveSpeed = 5.0f;private Rigidbody rb;private float horizontalInput;private float verticalInput;void Start(){rb = GetComponent<Rigidbody>();}void FixedUpdate(){horizontalInput = Input.GetAxis("Horizontal");verticalInput = Input.GetAxis("Vertical");Vector3 movement = new Vector3(horizontalInput, 0.0f, verticalInput);rb.AddForce(movement * moveSpeed * Time.fixedDeltaTime, ForceMode.VelocityChange);}
}

4、transform.Translate方法:接受一个向量参数,表示要移动的方向和距离。

public class PlayerController : MonoBehaviour
{public float moveSpeed = 5.0f;public float rotateSpeed = 100.0f;// Update is called once per framevoid Update(){// 获取水平和垂直输入轴的值float horizontalInput = Input.GetAxis("Horizontal");float verticalInput = Input.GetAxis("Vertical");// 计算移动方向Vector3 movement = new Vector3(horizontalInput, 0.0f, verticalInput);// 移动游戏对象transform.Translate(movement * moveSpeed * Time.deltaTime);// 计算旋转方向Vector3 rotation = new Vector3(0.0f, horizontalInput, 0.0f);// 根据旋转方向计算旋转角度float rotationAngle = Vector3.SignedAngle(transform.forward, rotation, Vector3.up);// 计算旋转速度float rotationSpeed = Mathf.Clamp(Mathf.Abs(horizontalInput), 0.0f, 1.0f) * rotateSpeed;// 围绕游戏对象的y轴旋转transform.Rotate(0.0f, rotationAngle * rotationSpeed * Time.deltaTime, 0.0f);}
}

5、 Mathf.Lerp 函数可以平滑地将一个值从一个范围过渡到另一个范围。

//var t = 1 / ((transform.position - targetPosition).magnitude);//匀速移动
//gameObject.transform.position = Vector3.Lerp(transform.position, targetPosition, t*0.01f);public class PlayerController : MonoBehaviour
{public float moveSpeed = 5.0f;public float smoothTime = 0.3f;// Update is called once per framevoid Update(){// 获取水平和垂直输入轴的值float horizontalInput = Input.GetAxis("Horizontal");float verticalInput = Input.GetAxis("Vertical");// 计算移动方向Vector3 movement = new Vector3(horizontalInput, 0.0f, verticalInput);// 计算目标位置Vector3 targetPosition = transform.position + movement * moveSpeed;// 平滑地移动游戏对象transform.position = Vector3.Lerp(transform.position, targetPosition, smoothTime);}
}

6、 Vector3.SmoothDamp 函数:接受四个参数:current:当前值;target:目标值;currentVelocity:当前速度,这个值会在函数中被修改以实现平滑过渡;smoothTime:平滑时间,表示从当前值到目标值所需的时间。

public class PlayerController : MonoBehaviour
{public float moveSpeed = 5.0f;public float smoothTime = 0.3f;private Vector3 velocity = Vector3.zero;// Update is called once per framevoid Update(){// 获取水平和垂直输入轴的值float horizontalInput = Input.GetAxis("Horizontal");float verticalInput = Input.GetAxis("Vertical");// 计算移动方向Vector3 movement = new Vector3(horizontalInput, 0.0f, verticalInput);// 计算目标位置Vector3 targetPosition = transform.position + movement * moveSpeed;// 平滑地移动游戏对象transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);}
}

7、MoveTowards 方法:接受三个参数:当前位置、目标位置和移动速度。

public class PlayerController : MonoBehaviour
{public float moveSpeed = 5.0f;// Update is called once per framevoid Update(){// 获取水平和垂直输入轴的值float horizontalInput = Input.GetAxis("Horizontal");float verticalInput = Input.GetAxis("Vertical");// 计算移动方向Vector3 movement = new Vector3(horizontalInput, 0.0f, verticalInput);// 计算目标位置Vector3 targetPosition = transform.position + movement * moveSpeed;// 平滑地移动游戏对象transform.position = Vector3.MoveTowards(transform.position, targetPosition, moveSpeed * Time.deltaTime);}
}

8、Move 方法:接受一个向量参数,表示要移动的方向和距离。

public class PlayerController : MonoBehaviour
{public float moveSpeed = 5.0f;private CharacterController controller;private float horizontalInput;private float verticalInput;void Start(){controller = GetComponent<CharacterController>();}void FixedUpdate(){horizontalInput = Input.GetAxis("Horizontal");verticalInput = Input.GetAxis("Vertical");Vector3 movement = new Vector3(horizontalInput, 0.0f, verticalInput);controller.Move(movement * moveSpeed * Time.fixedDeltaTime);//controller.SimpleMove(movement * moveSpeed);//接受一个向量参数,表示要移动的方向和距离,同时会自动处理重力和碰撞检测。}
}
http://www.jmfq.cn/news/5304133.html

相关文章:

  • 做网站的人叫什么软件/三叶草gw9356
  • 多语言网站思路/夸克搜索引擎入口
  • 郑州推广网站/seo方案书案例
  • 视频优化网站怎么做/网络推广费用计入什么科目
  • 桂阳网站设计/最强大的搜索引擎
  • 网站建设设计 网络服务/长沙靠谱seo优化
  • 如何做网站价格策略/防止恶意点击软件管用吗
  • 电商型网站建设/谷歌优化seo
  • 网站开发前端好还是后端好/潮州seo
  • 免费建站平台哪个稳定/购物网站有哪些
  • 作为一个大学生网站 应该怎么做/百度号码认证平台取消标记
  • python 网站开发教程/海外营销推广
  • 做网站设计答辩问题/百度号码认证平台官网首页
  • 个人主页搭建/新乡seo公司
  • 珠海网络公司网站建设/镇江seo公司
  • 中山网站建设sipocms/品牌软文
  • 做网站推销手表/佛山做网络优化的公司
  • WordPress手动切换主题/优化推广seo
  • 做网站要学什么c语言/优化大师下载电脑版
  • 网站用户运营/壹起航网络推广的目标
  • 没有自己的境外网站怎么做谷歌推广/全媒体运营师报考官网在哪里
  • 佛山做网站的哪个好/网站查询地址
  • wordpress设置上传/台州网站优化公司
  • 凡科做网站怎么样/长尾关键词挖掘精灵官网
  • 为什么我的网站备案通过还是显示未备案/关键词排名霸屏代做
  • 网站做web服务器/网站优化资源
  • 免费使用个人网站/移动网站推广如何优化
  • 山东省住房建设部网站/百度关键词搜索引擎排名优化
  • 试用网站要怎么做/网络营销是做什么的
  • 微信官方网站是多少钱/seo营销推广平台