- Home /
Question by
PanzerPotato · Dec 30, 2017 at 11:58 PM ·
physicsrigidbodycolliderswheelcolliderwheel
Wheelcolliders stuck in ground
Hello,
I intend on creating a tank prototype for my game, and the only problem is that the tank refuses to move unless I drag it extremely high up in the scene view, and accelerate as I am driving. Then everything works fine, until it comes to a stop again. What am I doing wrong?
This is the (C#) test script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using cakeslice;
public class ImportedTestScript : MonoBehaviour {
public Outline[] outline;
public string upKey;
public string downKey;
public string leftKey;
public string rightKey;
public bool canDrive = true;
public float speed;
public float turnSpeed;
public Rigidbody rb;
void Start () {
rb = GetComponent<Rigidbody> ();
foreach (Outline o in outline) {
o.enabled = false;
}
}
void FixedUpdate () {
if (Input.GetKey(upKey) && canDrive) {
rb.AddForce (transform.forward * speed * Time.deltaTime, ForceMode.Acceleration);
} else if (Input.GetKey(downKey) && canDrive) {
rb.AddForce (-transform.forward * (speed / 2) * Time.deltaTime, ForceMode.Acceleration);
}
if (Input.GetKey (rightKey)) {
rb.AddTorque (Vector3.up * turnSpeed * Time.deltaTime, ForceMode.Acceleration);
//transform.Rotate (transform.up * turnSpeed * Time.deltaTime);
} else if (Input.GetKey (leftKey)) {
rb.AddTorque (Vector3.down * turnSpeed * Time.deltaTime, ForceMode.Acceleration);
//transform.Rotate (-transform.up * turnSpeed * Time.deltaTime);
}
}
void OnMouseOver () {
foreach (Outline o in outline) {
o.enabled = true;
}
}
void OnMouseExit () {
foreach (Outline o in outline) {
o.enabled = false;
}
}
}
The Outline[]
is another script I am using.
Thanks!
Comment
Your answer
Follow this Question
Related Questions
Calculate Distance using WheelColliders 3 Answers
Not all sides of a cube collide properly( with pic) 2 Answers
How does wheelcollider mass factor into rigidbody mass? 1 Answer
Creating a simple wheel 0 Answers
Colliders next to each other 0 Answers