- Home /
Update breaks function
void Update()
{
if (Input.GetKeyDown("w"))
{
Fire();
}
}
void Fire()
{
rb.MovePosition(rb.position + Vector2.down * speed * Time.deltaTime);
}
I have the following code and every time I press W, the ball moves only down for 1 instead of multiplying with the speed variable. How can I make the object move as defined in the Fire().
Answer by Raimi · Jul 09, 2017 at 05:51 PM
I think you need to use +=
void Fire()
{
rb.position += Vector2.down * speed * Time.deltaTime;
}
Edit: Sorry Use this instead...
if(Input.GetKey(KeyCode.W))
{
rb.position += Vector2.down * speed * Time.deltaTime;
}
Answer by Jwizard93 · Jul 09, 2017 at 11:24 PM
You want to press W once and have the object continue on for forever?
MovePosition is one time kind of thing unless you call it all the time. Since it's a rigidbody try AddForce instead.
Your answer
Follow this Question
Related Questions
C# void FixedUpdate() only updating once 1 Answer
Finding object in update function not working. 0 Answers
why do these both codes work similarly when they are put inside update function... 2 Answers
Multiple Cars not working 1 Answer
why do these both codes work similarly when they are put inside update function... 3 Answers