[Unity]限制一个值的大小(Clamp以及Mathf)
2024-08-28 05:21:22
如何限制一个物体的运动范围?
- 代码实例
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. |
还有一些其他的函数想要查看可以查阅官方文档。
最新文章
- [LeetCode] Assign Cookies 分点心
- 多个插件依赖不同版本jQuery问题解决案例
- mybatis 添加事物后 无法获取自增主键的问题
- 【ASP.NET】编程点滴 :ASP.NET身份验证
- ONIX 实例
- NHibernate加载DLL错误
- Google Map API 学习四
- Codeforces 474F - Ant colony
- node.js + express(ejs) + mongodb(mongoose) 增删改实例
- 学生管理系统(C语言)
- java面试2(java技术栈和Hollis面试内容分享)
- [SCOI2010]幸运数字
- python实现简体中文和繁体相互转换
- Java Spring Boot VS .NetCore (八) Java 注解 vs .NetCore Attribute
- jenkins忘记admin密码解决办法
- zabbix基础使用--添加ping监控
- JDBC、JNDI和DBCP的区别
- 科学-建筑学-事务所:KPF
- pyqt 实现的俄罗斯方块
- POJ 3261 Milk Patterns 【后缀数组 最长可重叠子串】
热门文章
- 记录在linux上单机elasticsearch8和kibana8
- VB6查看桌面分辨率和工作区大小 2022.08.22 name.vt
- javax.script.ScriptException: Cannot find engine named: 'nashorn', ensure you set language field in JSR223 Test Element: JSR223 预处理程序
- 我服了!SpringBoot升级后这服务我一个星期都没跑起来!(上)
- centos使用lftp备份文件
- Git创建、diff代码、回退版本、撤回代码,学废了吗
- 区分mbr与gpt分区
- 记一次spark数据倾斜实践
- i春秋SQLi
- python进阶(28)import导入机制原理