I am completely new to unity and I’m having some trouble. I am trying to make a motorcycle game where the bike hits a object and an information box will pop up.
The main problem I’m having is that the bike doesn’t ‘stick’ to the terrain. The terrain has hills and valleys, and when your press the up arrow key for the bike to move forward, it does but gradually it goes down through the terrain. I have got the gravity on and tried changing the mass of the bike to make it stay on the terrain but it doesn’t. I’ve looked at numerous tutorials but I cant work out how to make it work, any advise and help would be amazing.
This is my code to get the bike moving with the arrow keys.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Movement : MonoBehaviour {
float Speed = 100.0f;
float RotationSpeed = 50.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.UpArrow)){
transform.Translate(Vector3.forward * Time.deltaTime * Speed, Space.Self);
}
if(Input.GetKey(KeyCode.DownArrow)){
transform.Translate(Vector3.forward * Time.deltaTime * -Speed, Space.Self);
}
if(Input.GetKey(KeyCode.LeftArrow)){
transform.Rotate(Vector3.up * Time.deltaTime * -RotationSpeed, Space.Self);
}
if(Input.GetKey(KeyCode.RightArrow)){
transform.Rotate(Vector3.up * Time.deltaTime * RotationSpeed, Space.Self);
}
}
}




