Alright, I’m working on a simple tank movement script and came across this. It works just fine until I run into a wall, or rather, don’t run into it. I know transform.Translate doesn’t take have a collision detection system, and so I’m looking for a workable alternative. Problem is, every possibility I’ve found sends up an error. Usually that it exist in the context, so I keep looking for other ways.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public float movementSpeed = 10;
public float turningSpeed = 60;
void Update() {
float horizontal = Input.GetAxis("Horizontal") * turningSpeed * Time.deltaTime;
transform.Rotate(0, horizontal, 0);
float vertical = Input.GetAxis("Vertical") * movementSpeed * Time.deltaTime;
transform.Translate(0, 0, vertical);
}
}
What if you would use a box collider, a rigidbody and wheel colliders? You could even reproduce the tank movement simply by applying motor torque to both wheels on one side.
– fafaseThats a possibility. The main issue is that there is a very picky mesh that doesn't always want to cooperate, so I'll give this a shot and see where it gets me.
– dontpanic4242So the box collider works, and but the rigidbody tends to cause the tank to slide away after a collision, like its on ice. It also forces me to only turn left for some reason.
– dontpanic4242Give it a large mass. And maybe you could constraint its movements. But first give it a 3000 mass or more.
– fafaseNah. It's mass isn't the issue.
– dontpanic4242