- Home /
How to get a character to slowly move onto screen
EDit: Clarification Here is the desired effect
- Player Spawns (or ReSpawns)
- He starts at a position off camera on X axis
- The player slowly moves onto screen
- This Effect should be visible over a few frames (this shouldn't happen instantly)
If you don't have answer, can you point me in the direction of this information? Thanks.
Old Info Below:
Hi All,
I am doing a top down shooter (1945) I would like the player to move smoothly onto the screen from off screen. To explain, the camera is fixed overhead, the player will start in a position that is not visible. When the player is at the correct position, (in this case X) I want the player to be able to control the ship. Below is my attempt. The character simply starts at his spawn point, and does not move any further. What am I doing wrong? I can explain further, let me know if this is unclear.
Instantiate(Player, Vector3(-43, 114, 4.5), Quaternion.Euler(0, -180,0));
function Update () {
while(transform.position.x < 10)
{
// move the ship on screen
var amtTomove = shipmoveonscreen * Time.deltaTime ;
transform.position = new Vector3(transform.position.x + amtTomove, transform.position.y, transform.position.z);
}
if (state != state.Explosion)
{
var playervertical = (playerSpeed * Input.GetAxis ("Vertical") )* Time.deltaTime;
transform.Translate(Vector3.left * playervertical);
}
}
I apologize for the code readability.... It may be a bit unclear.
Answer by Bunny83 · Mar 10, 2011 at 03:51 PM
I think your problem is your while loop. A while loop is executed within one frame. So if you enter the Update function the while loop will increment the position until it's greater or equal 10.
Just replace the while
by an if
if(transform.position.x < 10){
ps. take a look at the FAQs and the Editing Help.
Thanks, but this does not seem to work. Further, i changed the starting value of transform.position.x to -75, but the player object is still instantiating to -43. I don't think I have any other functions that instantiate the player object.
wait, why do you instantiate the player? To what object it this script attached to? It can not instantiate the player and control him. The script that controls the player have to be on the player object and if you instantiate the player via script you have to do this from another script. Some kind of game controller script. Does the instantiate line even belong to this script? It should work, and since you correctly used Time.deltaTime it should move with "shipmoveonscreen" units per sec. If you have another script that is involved you can add it to your question. Just edit it at anytime.
Your answer
Follow this Question
Related Questions
Jittery Movement (2D) 4 Answers
Player rotation affecting Top Down 2D Movement 1 Answer
Character movement problem, floats away 1 Answer
Making side-scrolling movement? 0 Answers