How to do without Rigidbody, rotate the object along the Y axis in both directions, and move the object forward in the right direction? How can you add acceleration and inertia to an object?
CodePudding user response:
You can have a look at the Unity Documentation Here, or look at code provided.
float horizontalSpeed = 2.0f;
float verticalSpeed = 2.0f;
float speed = 10.0f;
void Movement()
{
// Get the horizontal and vertical axis.
// By default they are mapped to the arrow keys.
// The value is in the range -1 to 1
float x = Input.GetAxis("Vertical");
float z = Input.GetAxis("Horizontal");
// Make it move 10 meters per second instead of 10 meters per frame...
var moveVector = new Vector3(x, 0 , 0);
// Move translation along the object's z-axis
transform.Translate(moveVector * Time.deltaTime);
}
void Rotation()
{
// Get the mouse delta. This is not in the range -1...1
float h = horizontalSpeed * Input.GetAxis("Mouse X");
float v = verticalSpeed * Input.GetAxis("Mouse Y");
transform.Rotate(v, h, 0);
}