I have the following script:
public float speed = 1;
public float jumpForce = 1;
private Rigidbody2D playerBody;
private float trueSpeed;
private float trueJumpForce;
void Start()
{
playerBody = GetComponent<Rigidbody2D>();
}
void Update()
{
if (Input.GetKeyDown("d"))
{
trueSpeed = speed * Time.deltaTime;
}
else if (Input.GetKeyDown("a"))
{
trueSpeed = speed * -1 * Time.deltaTime;
}
else if (Input.GetKeyDown("w"))
{
trueJumpForce = jumpForce * Time.deltaTime;
}
else
{
trueSpeed = 0.0f;
trueJumpForce = 0.0f;
}
playerBody.AddForce(new Vector2(trueSpeed, trueJumpForce), ForceMode2D.Impulse);
}
but if I run it, the player will fall through everything. I have a ground element which it should land on, but how do I do that?