Moving GameObject on Direction Faced by its Child

Hi, I am trying to move a GameObject (Player) toward the direction its child component (MOVER2) is facing. This simple line of code in the FixedUpdate () function of the Player script, work if left on its own moving automatically the Player in a direction, but when I insert it in the “if” statement it works only once each time I press the key, so that if I keep it pressed for a longer time, with the intention of making the movement repeat, nothing happen.

Is there a way to obtain a continuous movement using this code? or should totally change it with some other that specify the amount of movement for each frame? I know it is a simple matter but I am a beginner and a tried all the movement method I found out there, without success. Thank you for your time!

if 
(Input.GetKeyDown(KeyCode.Space))
{
   this.transform.position += MOVER2.transform.right * movespeed;
}

well GetKeyDown or GetButtonDown will only activate once per Input press/click. GetKeyUp or GetButtonUp will activate once the button is released. GetKey or GetButton will run as long as the button is clicked/pressed. Its a crude explanation but if i understood correctly should point you in the right direction.

1 Like

Seems to be what I am looking for! I will try it soon, however my final input device is not my keyboard and the input I get keeping my button pressed is a series of “1” which I am afraid will be recognised as pressing the button fast. However, will try it and if I keep having problems I may search or open another tread, thanks!