# Unity - How to move a user controlled animated gameobject programmatically?

I have a player controlled gameObject with an attached script and animator with it's related animations. It all works great.

However the gameObject is on screen immediately on level startup.

I want to have the gameObject start off-screen so that story dialog can be displayed first and once completed the player gameObject will move onto the screen and then come under the players control.

I have been able to create a separate animator state for the "off-screen to on-screen" animation and it can be triggered separately in code. But I can't work out the logic needed to get the gameObject to do what I want.

In the enclosed image the PaddleIdle state keeps the paddle off screen. The PaddleStartup state moves the gameObjects position onto the screen. Once on-screen, the PaddleNormal state is supposed to start the gameObjects normal animations and allow player control.

I have tried a default transition from PaddleStartup to PaddleNormal but it performs one "PaddleStartup" sequence and then there is nothing.

I know I am missing something either I am not configuring a transition correctly or I am not scripting this correctly, can someone advise me on things I might try?

Thank you so much for your help

• Have you tried creating a trigger-controlled transition from PaddleIdle to PaddleStartup? – Kevin H. Sep 27 '17 at 9:39

You have not given enough info. But you can use something like this (the code may differ depending on the version):

...
if (this->sceneManager.currentScene == "boot") {
this->_status = INVISIBLE;
}
...
...
If (this->_status == INVISIBLE) {
this->player.playAnimation("invisible");
}


You can add an invisible animation in the void Player::setupAnimations(...) function, in which there are sprites with only a black background. The this->_status = INVISIBLE; statement means there is a global enumeration called _status like given below:--

In the file globals.h:

...
enum PlayerStatus {
ALIVE,
INVISIBLE
}
...


And, in the file 'player.cs' (for your player gameObject):

...
protected:
PlayerStatus _status;
...


If the current scene is displaying your game's title then the _status will be INVISIBLE. and if the _status is INVISIBLE, the "invisible" animation will be played.

Hope that helped.