Hello, I’m messing around in Unity and I want force to apply to a cube only one when i press “s”
I have tried this following method:
public float force = 5000f;
if (Input.GetKeyDown (KeyCode.S))
rb.AddForce(0, 0, force);
Debug.Log(“Launch”);
if (force > 5000)
force = 5000;
if i repeatedly “s” then the force will increase by increments of 5000 rather than staying at 5000 now matter how many times i press the s key.
using UnityEngine;
public class player : MonoBehaviour
{
public Rigidbody rb;
public float force = 5000;
public float sideforce = 500;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
rb.AddForce(0, 0, force);
Debug.Log("Launch");
if (Input.GetKey(KeyCode.RightArrow))
{
Debug.Log("Left Movement");
rb.AddForce(sideforce * Time.deltaTime, 0, 0);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
Debug.Log("Right Movement");
rb.AddForce(-sideforce * Time.deltaTime, 0, 0);
}
}
}
Thank you