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 · Apr 26, 2011 at 11:22 AM · 2drotationmovementplayershmup

How to create a player movement with Rotation?

Hello,

I'm trying to create a top down 3d Shooter. (Air attack HD) I'm trying to figure out how to get the player's ship to "roll" left or right when the player uses the horizontal keys. So far, I've figured this out:

1) Check to see if the player has pressed the "D" Horizontal Move key 2) Move the player's ship (Done in another part of the code) 3) Rotate the player's ship to -35 degrees 4) Wait some time 5) Move the player's ship back to original rotation

The problem is, the ship object never rotates back to it's normal rotation/position. How do I fix this. Here's the code that I have so far.

function PlayerShipRoll () { //////Fix this! // value = Input.GetKey ("W"); if (Input.GetKey (KeyCode.A)) { transform.Rotate(0, 0,0); yield ; transform.Rotate(0, 0,0); //transform.rotation.x = Mathf.Clamp(transform.rotation.x, 25, 0); print ("Horizontal key was pressed"); } if (Input.GetKeyDown (KeyCode.D)) { transform.Rotate(-35,0, 0); transform.rotation.x = Mathf.Clamp(transform.rotation.x, 0 ,0 ); yield WaitForSeconds(2) ; transform.Rotate (180,180,0); }

}

Comment
Add comment · Show 5
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 Eric5h5 · Apr 26, 2011 at 11:50 AM 0
Share

For a start, transform.rotation is a quaternion, and rotation.x isn't what you're thinking. Use eulerAngles, or Quaternion.Euler.

avatar image Owen-Reynolds · Apr 27, 2011 at 12:49 AM 0
Share

There are a number of answered Q's for pretty much the same thing on here. If that worked, it would "snap" tilted, then back. $$anonymous$$ost are using Lerp to get a gradual move. Search around for that stuff.

avatar image Marvin Hawkins · Apr 28, 2011 at 11:48 AM 0
Share

Thanks for the Response Guys. I actually came up with the below. This works, but I'm having trouble getting it to "snap" in place. The player's ship rotates, and goes back to it's original rotation.

The lerp idea sounds cool, but Quaternion doesn't seem to work with a transform. Any thoughts?

 if(Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.D))
 {
       
       
     transform.Rotate(-45,0,0);
     transform.rotation.x = $$anonymous$$athf.Clamp(-50, 0 ,0 );
     yield WaitForSeconds(2) ;
     transform.Rotate (0,0,0);
 }
avatar image Owen-Reynolds · Apr 29, 2011 at 04:58 AM 0
Share

Look up clamp. It's just a shortcut for saying "can't be less than X or more than Y." Rotate(0,0,0) is pretty much the same thing as adding 0. Look at Euler angles to say "this is my new rotation."

avatar image Marvin Hawkins · May 08, 2011 at 05:57 PM 0
Share

Thanks Owen makes sense but I want the object to go back to it's original position which would be 0 0 0 or close to it

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Marvin Hawkins · May 03, 2011 at 11:46 AM

This is not an actual answer, but I haven't figured this out, and can still use some help.

var  playerhorizontal  = (playerSpeed * Input.GetAxis ("Horizontal") )* Time.deltaTime;

horizontalmove = new Vector3(0,0,1); transform.Translate(horizontalmove * playerhorizontal); transform.Rotate(playerhorizontal, 0, 0); enter code here

The transform.Rotate(playerhorizontal,0,0); line does the trick, but I still can't get the ship to snap back into place. Any thoughts?

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 · May 04, 2011 at 11:09 AM 0
Share

This video does the best job of showing the type of movement that I'm looking for. It shows the ship movement from side to side with a slight "banking" rotation. Any thoughts?

http://www.youtube.com/watch?v=3PYhDgS6Ecg

avatar image xReaper7x · Feb 24, 2014 at 08:50 PM 0
Share

This can easily be achieved using animations.

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

1 Person is following this question.

avatar image

Related Questions

How do i rotate my player in moving direction in 2d? 0 Answers

Rotate/Flip Image in Unity 2d using Virtual Joystick 1 Answer

Curve player movement 1 Answer

Unity 2D: How can i get my sprite to rotate to the direction I am going? 1 Answer

Rigidbody.AddForce and incorrect rotation 2 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