Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Modifying controls on code help

$
0
0
Hey all I need help with a car code I found on a tutorial. I would like to modify the controls so that the car only moves via the arrow keys, the code at the moment uses the arrows and WASD and also the space bar for controls. I'm new to coding and I'm not asking you to do this for me but I'd just like some help thanks. Here is the code: //CarController1.js var wheels : Transform[]; var enginePower=150.0; var power=0.0; var brake=0.0; var steer=0.0; var maxSteer=25.0; function Start(){ rigidbody.centerOfMass=Vector3(0,-0.5,0.3); } function Update () { power=Input.GetAxis("Vertical") * enginePower * Time.deltaTime * 250.0; steer=Input.GetAxis("Horizontal") * maxSteer; brake=Input.GetKey("space") ? rigidbody.mass * 0.1: 0.0; GetCollider(0).steerAngle=steer; GetCollider(1).steerAngle=steer; if(brake > 0.0){ GetCollider(0).brakeTorque=brake; GetCollider(1).brakeTorque=brake; GetCollider(2).brakeTorque=brake; GetCollider(3).brakeTorque=brake; GetCollider(2).motorTorque=0.0; GetCollider(3).motorTorque=0.0; } else { GetCollider(0).brakeTorque=0; GetCollider(1).brakeTorque=0; GetCollider(2).brakeTorque=0; GetCollider(3).brakeTorque=0; GetCollider(2).motorTorque=power; GetCollider(3).motorTorque=power; } } function GetCollider(n : int) : WheelCollider{ return wheels[n].gameObject.GetComponent(WheelCollider); }

Viewing all articles
Browse latest Browse all 1875

Trending Articles



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