Answer the question
In order to leave comments, you need to log in
How to fix the code so that the object is only directed in a straight line, without "drifting"?
Hello, here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateTank2 : MonoBehaviour
{
public Transform Selftransform;
private Vector3 _force;
private int rotate = 1;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
Selftransform.position += _force;
if (rotate == 1)
{
transform.Rotate(0, 0, 2);
}
if (Input.GetKey(KeyCode.D))
{
rotate = 0;
_force += (Selftransform.up * Time.deltaTime) * 0.1f;
}
else
{
_force = Vector3.Lerp(_force, Vector3.zero, 10);
rotate = 1;
}
}
}
Answer the question
In order to leave comments, you need to log in
1. Turn off collision physics and move through transform
2. or use a perfectly elastic material and turn off roll and roll inertia.
There is a "look at" function - lookAt(target.tranform.position); change the rotation so that the blue arrow points forward of the tank and apply this function, it should work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question