Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Unity Engine math APIs

Use the collection of math APIs in the Unity.Engine namespace to access common mathematical operations.
Read time 1 minuteLast updated 6 days ago

The
UnityEngine
includes math APIs best-suited for use in projects that are just-in-time (JIT) compiled with the Mono scripting backend. This includes the
Mathf
class for common math functions, including trignomometric, logarithmic, and other oprations. It also includes classes for data structures such as
Vector2
,
Vector3
,
Matrix4x4
,
Quaternion
, and
UnityEngine.Random
.
The
UnityEngine
math APIs are recommended for code that is not Burst compiled. In Burst compiled code, use the Unity.Mathematics APIs instead, which are optimized for Burst compilation.

Topic

Description

Common math functions with the Mathf classUse Unity's
Mathf
class to apply trigonometric, logarithmic, and other math functions commonly required in game development.
Moving objects with the Vector classesPerform vector arithmetic with Unity's 2D, 3D, and 4D vector classes to manage the position and speed of objects and the distance between them.
Generating random numbers with the Random classUse the
Random
class to generate various types of random values commonly required in game development.
Controlling rotation with the Quaternion classUse euler angles or quaternions in Unity's left hand coordinate system to control the rotation and orientation of GameObjects.

Additional resources