如何限制一个物体的运动范围?


  • 代码实例
public float xMin, xMax, zMin, zMax;
rigidbody.position = new Vector3(
Mathf.Clamp(rigidbody.position.x,xMin,xMax),
0.0f,
Mathf.Clamp(rigidbody.position.z,zMin,zMax)
);

通过上述代码我们可以限制其在x轴以及z轴的运动范围,其范围大小我们可以在unity editor中进行输入。

关于Mathf类


  • Description



    A collection of common math functions.

  • Static Properties

属性名 简介
Deg2Rad Degrees-to-radians conversion constant (Read Only).
Epsilon A tiny floating point value (Read Only).
Infinity A representation of positive infinity (Read Only).
NegativeInfinity A representation of negative infinity (Read Only).
PI The infamous 3.14159265358979… value (Read Only).
Rad2Deg Radians-to-degrees conversion constant (Read Only).

- Static Methods(仅包含一些常用的方法,需要查询则转向官方手册)

函数名 简介
Abs Returns the absolute value of f.
Clamp Clamps a value between a minimum float and maximum float value.
Sin Returns the sine of angle f.
Cos Returns the cosine of angle f.
Log Returns the logarithm of a specified number in a specified base.

还有一些其他的函数想要查看可以查阅官方文档。

最新文章

  1. [LeetCode] Assign Cookies 分点心
  2. 多个插件依赖不同版本jQuery问题解决案例
  3. mybatis 添加事物后 无法获取自增主键的问题
  4. 【ASP.NET】编程点滴 :ASP.NET身份验证
  5. ONIX 实例
  6. NHibernate加载DLL错误
  7. Google Map API 学习四
  8. Codeforces 474F - Ant colony
  9. node.js + express(ejs) + mongodb(mongoose) 增删改实例
  10. 学生管理系统(C语言)
  11. java面试2(java技术栈和Hollis面试内容分享)
  12. [SCOI2010]幸运数字
  13. python实现简体中文和繁体相互转换
  14. Java Spring Boot VS .NetCore (八) Java 注解 vs .NetCore Attribute
  15. jenkins忘记admin密码解决办法
  16. zabbix基础使用--添加ping监控
  17. JDBC、JNDI和DBCP的区别
  18. 科学-建筑学-事务所:KPF
  19. pyqt 实现的俄罗斯方块
  20. POJ 3261 Milk Patterns 【后缀数组 最长可重叠子串】

热门文章

  1. 记录在linux上单机elasticsearch8和kibana8
  2. VB6查看桌面分辨率和工作区大小 2022.08.22 name.vt
  3. javax.script.ScriptException: Cannot find engine named: 'nashorn', ensure you set language field in JSR223 Test Element: JSR223 预处理程序
  4. 我服了!SpringBoot升级后这服务我一个星期都没跑起来!(上)
  5. centos使用lftp备份文件
  6. Git创建、diff代码、回退版本、撤回代码,学废了吗
  7. 区分mbr与gpt分区
  8. 记一次spark数据倾斜实践
  9. i春秋SQLi
  10. python进阶(28)import导入机制原理