Car coding help
I am making a simple racing game and am working on the player script for the first car and im having some problems with it. I cant seem to reduce the speed of said car even though I can reduce the turning speed, it wont build up to the speed it's set to and for some reason it stopped jumping off the ramps i built. I know i may be missing some codes but any help is appreciated
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
private Rigidbody rb;
private float hoverHeight = 1.0f;
private float terrainHeight;
private Vector3 pos;
public KeyCode pressLeft;
public KeyCode pressRight;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float v = Input.GetAxis("Vertical") * 1;
Vector3 vel = rb.velocity;
vel.z = v;
rb.velocity = vel;
// Apply motion along the z axis of the car
transform.Translate(0, 0, Input.GetAxis
("Vertical"));
// Apply motion along the y axis of the object
transform.Rotate(0, Input.GetAxis
("Horizontal") * 5, 0);
pos = transform.position;
float terrainHeight = Terrain.activeTerrain.SampleHeight(pos);
transform.position = new Vector3(pos.x,
terrainHeight + hoverHeight,
pos.z);
}
}
Comment
Your answer
Follow this Question
Related Questions
Buttons for Player movement 0 Answers
Character Diagonal Movement Issue 3 Answers
Switching lanes 1 Answer
Rotating object towards (0,0,0) during idle (no input) 0 Answers
Jump Using Raycast. 0 Answers