I need help to make this cube go vertically and jump from one side to another. This is the script i have for now. I am a beginner at using this and been trying to find out for last week but no success can you help me with scrips and explanations please. Thank you in advance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CubeController : MonoBehaviour {
public float cubespeed;
public float moveSpeed;
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
// Update is called once per frame
void Update () {
float xSpeed = Input.GetAxis("Horizontal");
Rigidbody body = GetComponent<Rigidbody>();
body.AddTorque(new Vector3(xSpeed, 0) * cubespeed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
}