Mathf.Clamp
in the game, in order to limit the movement of a certain axis of the player within a certain range, mathf.clamp can be used to solve the problem
Mathf.Clamp(float value,float min,float max)
Pass in three parameters in mathf. Clamp: value, min, max
Limit the value between min and max. if value is greater than max, Max is returned. If value is less than min, min is returned. Otherwise, value is returned
For example:
_ rig.transform.position = new Vector3(transform.position.x, transform.position.y,
Mathf.Clamp(_ rig.transform.position.z, -20.0f, 28.0f));
Here, the movement of the rigid body in the z-axis direction is limited, and the rigid body moves in the range of – 20.0 to 28.0
Similar Posts:
- Unity realizes lookat in 2D
- Failed to create agent because it is not close enough to the NavMesh
- Rigidbody.moveposition rigid body movement
- Keras.utils.to in keras_ Categorical method
- Unity – NullReferenceException: Object reference not set to an instance of an object
- Unity awesome plug-in Final IK
- Unity 3D physics Manager
- TypeError: not enough arguments for format string
- Python TypeError: softmax() got an unexpected keyword argument ‘axis’
- [ERROR] error: java.lang.StackOverflowError, at scala.tools.nsc.transform.Erasure$Eraser.adaptMember(Erasure.scala:646)