Quantcast
Channel: Questions in topic: "wheelcollider"
Viewing all articles
Browse latest Browse all 490

Wheelcolliders stuck in ground

$
0
0
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 (); 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!

Viewing all articles
Browse latest Browse all 490

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>