Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Marvin Hawkins · Mar 10, 2011 at 01:36 PM · 2dmovementshooter

How to get a character to slowly move onto screen

EDit: Clarification Here is the desired effect

  1. Player Spawns (or ReSpawns)
  2. He starts at a position off camera on X axis
  3. The player slowly moves onto screen
  4. 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);
 }

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Marvin Hawkins · Mar 10, 2011 at 02:02 PM 0
Share

I apologize for the code readability.... It may be a bit unclear.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Marvin Hawkins · Mar 11, 2011 at 01:29 AM 0
Share

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.

avatar image Bunny83 · Mar 11, 2011 at 12:25 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How can i add simple back and forth movement on the Y-axis to an enemy that has velocity on the X-axis attached to it? 3 Answers

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges