Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 derpman1298 · Apr 26, 2019 at 06:43 AM · rotationmovement2d game

Change the z rotation of my player?,how to adjust the z rotation of my player?

Hello, i am very new to unity, programming and C#. I have a small game set up where there is a player object in a river, and rocks spawn above and move straight down. when the player colides with the rocks, they rotate. since im going with a "Canoe" vibe i like this, but i want the canoe to slowly correct itself like its being paddled by a person. i was thinking a statment that checks if the canoe is the default rotation (in this case 180 degrees) and if it isnt issues a rotation force to correct it. any advice is appreciated, thanks!

 public float speed = 15.0f;

 public float maxVelocity = 4.0f;

 private Vector2 screenBounds;

 // Start is called before the first frame update
 void Start()
 {
     screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
 }

 // Update is called once per frame
 void Update()
 {
     PlayerMoveKeyboard();

     //PlayerMoveKeyboardwasd();

     if (transform.position.y < -screenBounds.y)
     {
         Destroy(this.gameObject);
     }
     //where im trying to get the rotation
     if (gameObject.transform.rotation.eulerAngles.z < 180)
     {
         
     }

     if (gameObject.transform.rotation.eulerAngles.z > 180)
     {
      
     }

 }
 //Moving With Arrow keys
 void PlayerMoveKeyboard()
 {
     //force that pushes the player
     float force = 0.0f;
     //Max Velocity Of The Player
     float velocity = Mathf.Abs(GetComponent<Rigidbody2D>().velocity.x);
     //Get Horizonal Velocity
     float h = Input.GetAxis("Horizontal");

     if (h > 0)
     {
         if (velocity < maxVelocity)
         {
             force = speed;
         }

     }
     else if (h < 0)
     {
         if (velocity < maxVelocity)
         {
             force = -speed;
         }
     }
     GetComponent<Rigidbody2D>().AddForce(new Vector2(force, 0));
 }
 //Moving with WASD (Unfinished)
 void PlayerMoveKeyboardwasd()
 {
     float force = 0.0f;
     float velocity = Mathf.Abs(GetComponent<Rigidbody2D>().velocity.x);

     if (Input.GetKey(KeyCode.A))
     {

     }
     if (Input.GetKey("d"))
     {

     }
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CentauriDev · Apr 26, 2019 at 06:59 AM

You can use transform.Rotate

You can change rotateamount, the higher the faster it goes.

Example:

 Transform.Rotate(0,0,rotateamount)

Comment
Add comment · 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

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

202 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 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 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 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 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 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 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 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 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 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 avatar image avatar image

Related Questions

2D Zig-zag movement and rotation 1 Answer

Sprite will not roate when arrow keys are pressed 2 Answers

Turn character the way I am moving 2 Answers

Third Person Character Controller Movement 1 Answer

Rotation used as movement 4 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