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 LifeArtist · Mar 17, 2014 at 05:08 PM · 2dmoveanglemove an objectkey pressed

Unity2D move + turn with a fixed angle

Hello,

i have a question about moving a sprite object.

I'm using a rigidbody2D and i want a constant speed.

So i used rigidbody2D.velocity ( Maybe .AddForce is better but i want that the speed never fade away. And with Force it does :(.)

So when i press the left/right key the object should make a curve by a fixed angle.

http://curvefever.com/play2.php ( Just click play ) Like this game >.<

Maybe someone can help me.

Regards

LifeArtist

Comment
Add comment · Show 2
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 robertbu · Mar 17, 2014 at 05:33 PM 0
Share

Without your code, I cannot give focused, accurate answer. I'm guessing is that you need to add your force relative to the direction the object is facing ins$$anonymous$$d of a world direction. For example, if you are using Vector3.forward, change to using Transform.forward.

avatar image LifeArtist · Mar 17, 2014 at 05:55 PM 0
Share

Sry ... i didnt saw ur comment -.-"

 if (Input.Get$$anonymous$$ey(moveRight))
 {
     rigidbody2D.transform.Rotate(0F, 0F, 7F, Space.Self);
 }
 if (Input.Get$$anonymous$$ey(moveLeft))
 {
     rigidbody2D.AddForce(new Vector2(0F, 5F));
 }

I use Vector2 ... and my object just rotates and still moving up and down.

1 Reply

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

Answer by robertbu · Mar 17, 2014 at 07:55 PM

I'm assuming the 'forward' of your ship is the 'up' direction when the rotation is (0,0,0). Your code should be executed in FixedUpdate(). Try this to address your problem:

 void FixedUpdate() {
     if (Input.GetKey(moveRight))
     {
         transform.Rotate(0F, 0F, 7F);
     }
     if (Input.GetKey(moveLeft))
     {
         rigidbody2D.AddForce(transform.up * 5F);
     }
 }
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 LifeArtist · Mar 17, 2014 at 08:26 PM 0
Share

Omg great ! U have made my day :)

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

20 People are following this question.

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

Related Questions

Move Object With Angle In 2D 1 Answer

2D Movement Problems 2 Answers

2D Animation does not start 1 Answer

2D Character grabing the wall 1 Answer

How to change angle-roll object with mobile input? 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