Table of contents
to rotate
revolve around
Get control of the mouse
mouse control rotation
keyboard operation
Cameras and Lights
Rigidbodies and Colliders
1: rotate
Vector3.right: Indicates the positive direction of x
Vector3.left: Indicates the negative direction of x
Vector3.up: Indicates the positive direction of y
Vector3.down: Indicates the negative direction of y
Vector3.forward: Indicates the positive z direction
Vector3.back: Indicates the negative direction of z
2: Rotate around
CentPoint.position: coordinates around the center point
Vector3.up: angle of rotation
speed: the speed of rotation
Observation shows that the cube rotates around the center of the sphere and spins on itself
3: Get control of the mouse
1-> Get the left and right mouse buttons
Input.GetMouseButtonDown()
Input.GetMouseButton()
Input.GetMouseButtonDown()
2-> Get the mouse wheel
Input.GetAxis("Mouse ScrollWheel")!=0 (0 if the scroll wheel does not move)
4. Mouse control rotation
If there is no if judgment, this will follow the mouse to turn to realize the rotation of the object
5. Keyboard operation
//Get the keyboard
Input.GetKey(keyCode.A)
Input.GetKeyDown(keyCode.A)
Input.GetKeyUp(keyCode.A)
Use wasd to control the front, back, left, and right of the object
method one:
Method Two:
Method three:
Method four:
h represents the front and rear directions, v represents the left and right directions, when the object is still, h and v are both 0
Input.GetAxis() has a easing effect, which is equivalent to the inertia of the object and will not stop immediately
Input.GetAxisRaw() has no easing effect, it will stop immediately when there is no button
Method five:
Bounds the range of motion of an object
Example: Control the movement of the object back and forth, left and right, and use the mouse to control the horizontal rotation of the object
6. Camera and lights
The above code realizes that sliding the scroll wheel up can zoom in on the field of view, and sliding the scroll wheel down can zoom out the field of view, and clicking the right mouse button can return to the original field of view
7. Rigidbody and collider
rule:
Conditions for two objects to collide: 1->Both objects must have colliders
2->One of the objects must also have: Rigidbody
Rigidbody: Rigidbody
After adding a rigid body to the object, the UseGravity object will have gravity, where Mass is the mass of the object, Drag is the air resistance suffered by the object, and Angular Drag is the rotational resistance suffered by the object
Collider: Box Collider (cube) /Sphere Collider (spherical) /Capsule Collider (capsule)
Click Edit Collider to modify the size of the object's collision body
is Trigger: select whether it is a trigger