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 NeilJones313 · Feb 23, 2012 at 03:52 AM · speedkeypresscrossfadeshipkeydown

Moving ship to a point on keydown

Hi I'm having a problem. I have a ship that's in the middle of the screen. What I want to happen is when I hit the left arrow key the ship turns to the left a little and movers to the left of the screen, and when I hit the right key, it turns and moves to the right.

I know its most likely something really simple but Iv been killing myself the last two hours trying to get this to work. Anyone have any ideas?

Comment
Add comment · Show 6
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 ZweiD · Feb 23, 2012 at 07:56 AM 0
Share

what exactly are you trying to accomplish?

do you want the ship to move to the left / right while you are holding the button - or - do you want the ship to move to a certain worldposition when you press the button?

avatar image NeilJones313 · Feb 23, 2012 at 11:40 AM 0
Share

while holding the button i want the ship to move to a certain point and stay there until I let go, then it goes back to the middle point, if that makes any since.

avatar image ZweiD · Feb 23, 2012 at 11:45 AM 0
Share

yeah that sounds better.

do you want the ship to jump to the position or slowly move there? (btw. do you know iTween?)

give me a $$anonymous$$ute to write something down.

avatar image NeilJones313 · Feb 23, 2012 at 12:00 PM 0
Share

I just wanted to it go slowly there, yea but iTween isn't recognized whenever I make a new script Im most likely just doing it wrong?

avatar image ZweiD · Feb 23, 2012 at 12:03 PM 0
Share

did you download iTween from the asset store?

if not thats probably your problem.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by senad · Feb 23, 2012 at 09:52 AM

Have a look at this tutorial, character movement is explained in it: http://unity3d.com/support/resources/tutorials/3d-platform-game

Comment
Add comment · Show 1 · 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 NeilJones313 · Feb 23, 2012 at 11:51 AM 0
Share

Thanx senad, Iv seen the tutorial before it helped me a lot with other parts of my game but not so much about this one, because my ship is more of an object that that just moves to a point when i hit a key then moves back when I let go.

avatar image
0

Answer by ZweiD · Feb 23, 2012 at 12:02 PM

code in C#:

 // put the following code in your Update function
 
 float shipDistanceToCam = 10.0F;
 // getting the 3 points the ship jumps to
 Vector3 left = Camera.main.ScreenToWorldPoint(new Vector3(10,10,shipDistanceToCam));
 Vector3 mid = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width/2,10,shipDistanceToCam));
 Vector3 right = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width-10,10,shipDistanceToCam));
 
 if(Input.GetKey("left")) {
   gameObject.transform.position = left;
 } else if(Input.GetKey("right")) {
   gameObject.transform.position = right;
 } else {
   gameObject.transform.position = mid;
 }

cannot test the code at the moment, so be carefull

with this the ship jumps to the coordinates.

Comment
Add comment · Show 1 · 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 ZweiD · Feb 23, 2012 at 12:06 PM 0
Share

if you want it to go slowly to the position, try doing something like:

iTween.$$anonymous$$oveTo(gameObject, left, 5);

ins$$anonymous$$d of setting the position directly. (documentation for iTween: http://itween.pixelplacement.com/documentation.php )

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

On being Invoked by KeyPress, my gameobject appears alright, but does not get invoked again on key press ? 1 Answer

Key reading from inputString, backspace only works the first time 4 Answers

Forcing GetKeyDown by script. 2 Answers

Animation Stop and Stay 1 Answer

Rotation Speed 1 Answer


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