using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement_Script : MonoBehaviour
{
public Rigidbody rb;
public float forward_speed = -200;
public float left_speed = 50;
public float right_speed = 50;
public float backward_speed = 50;
public float jump_height = 20;
public float distToGround = 0f;
bool space_pressed = false;
// Update is called once per frame
void Update()
{
Debug.Log(Physics.Raycast(transform.position,Vector3.down, distToGround));
//Main loop
if (Input.GetKey("a")) {
rb.AddForce(0, 0, -1 *left_speed);
}
if (Input.GetKey("d")) {
rb.AddForce(0, 0, right_speed);
}
if (Input.GetKey("w")) {
rb.AddForce(forward_speed, 0, 0);
}
if (Input.GetKey("s")) {
rb.AddForce(backward_speed, 0, 0);
}
if (Input.GetKey("space")) {
if (Physics.Raycast(transform.position,Vector3.down, distToGround) == true) {
rb.AddForce(0, jump_height, 0);
}
}
}
}
This is my code, how do I make it so that my object rotates and goes in that direction?,using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement_Script : MonoBehaviour
{
public Rigidbody rb;
public float forward_speed = -200;
public float left_speed = 50;
public float right_speed = 50;
public float backward_speed = 50;
public float jump_height = 20;
public float distToGround = 0f;
bool space_pressed = false;
// Update is called once per frame
void Update()
{
Debug.Log(Physics.Raycast(transform.position,Vector3.down, distToGround));
//Main loop
if (Input.GetKey("a")) {
rb.AddForce(0, 0, -1 *left_speed);
}
if (Input.GetKey("d")) {
rb.AddForce(0, 0, right_speed);
}
if (Input.GetKey("w")) {
rb.AddForce(forward_speed, 0, 0);
}
if (Input.GetKey("s")) {
rb.AddForce(backward_speed, 0, 0);
}
if (Input.GetKey("space")) {
if (Physics.Raycast(transform.position,Vector3.down, distToGround) == true) {
rb.AddForce(0, jump_height, 0);
}
}
}
}
This is my code, I want to make it so that my cube rotates and goes in that direction like a car.