{
private Rigidbody2D rb;
private Transform trans;
public float top_height = 1.15f;
public float spd = 1f;
[SerializeField] float y_pos;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
trans = GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
y_pos = trans.position.y;
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("Space bar pressed");
Vector2 movement = new Vector2(0, -1);
rb.velocity = movement * spd;
}
else
{
Vector2 movement = new Vector2(0, 1);
rb.velocity = movement * spd;
}
}
}
hello, forgive me if this isnt sufficient context but im trying to make it so that an gameobjects y position lowers when the spacebar is pressed but otherwise will raise the y position until it reaches a given height. At the very least I would like help understanding how to make it so that when the space bar is pressed, the gameobject lowers