im very new to coding so sry if this is a simple mistake.
ive set up my cube to move in any direction but for some reason whenever i press a button to move i move in the direction i pressed but only for a split second even if i hold the key down. here is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ri : MonoBehaviour
{
private Rigidbody rb;
public int speed;
public int hspeed;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("w"))
{
rb.AddForce(transform.forward * 100);
}
if (Input.GetKeyDown("s"))
{
rb.AddForce(0, 0, -speed);
}
if (Input.GetKeyDown("a"))
{
rb.AddForce(hspeed, 0, 0);
}
if (Input.GetKeyDown("d"))
{
rb.AddForce(-hspeed, 0, 0);
}
}
}
↧