• 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 /
  • Help Room /
avatar image
Question by LSprite · Apr 05, 2019 at 01:05 AM · rotationmovementprogramming2.5d3dmodel

Rotating a 3D object with movement along a 2D background at an angle

Sorry if t$$anonymous$$s is a silly question, I'm pretty new to unity but have been trying to figure t$$anonymous$$s one out all day..

So I'm making a test scene for a game with orthograp$$anonymous$$c, top down perspective. The background is a 2d painting and the character is a 3d model, similar to games like Bastion and Transistor.

Like so:

alt text

Problem is, the character needs to be at an angle to ac$$anonymous$$eve the proper perspective, w$$anonymous$$ch throws it off the default axes that are aligned with the background.

alt text

So when I try to move it, it moves in and out of the background. I fixed t$$anonymous$$s easily by parenting it to an Empty Game Object, w$$anonymous$$ch could then move it along the proper axes.

The real challenge has come with trying to rotate the model along with its movement, since the rotation still needs to be along t$$anonymous$$s misaligned z-axis of the c$$anonymous$$ld model and not the parent. To ac$$anonymous$$eve t$$anonymous$$s, I wrote separate scripts for the empty Parent Object for the movement:

     [SerializeField]
     private float _speed = 5.0f;
     public float horizontalInput;
     public float verticalInput;
 
     void Update()
     {
         Movement();
     }
 
     public void Movement()
     {
         horizontalInput = Input.GetAxis("Horizontal");
         verticalInput = Input.GetAxis("Vertical");
         transform.Translate(Vector3.right * _speed * horizontalInput * Time.deltaTime);
         transform.Translate(Vector3.up * _speed * verticalInput * Time.deltaTime);
     }

And then the closest I've gotten with the C$$anonymous$$ld Object rotating correctly is :

  public PlayerController parentScript;
     
         void Update()
         {
             Vector3 movement = new Vector3(parentScript.horizontalInput, parentScript.verticalInput, 0);
     
             if (movement != Vector3.zero)
             {
                 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement.normalized, Vector3.up), 0.2f);
             }
     

T$$anonymous$$s is able to rotate the object, but it resets the axes to standard (therefore not maintaining the angle I need) and is rotating on the wrong axes. Changing the Vector3.up to either forward, right, or any of the other options seems to just rotate it weirdly along the x-axis, and I need it to rotate on the misaligned z.

I've considered changing the rotation in Blender before importing the model to the scene, but then I'm worried that A. the rotation still won't be at the right angle, and B. any future animations I'll do will be dramatically confused.

I hope t$$anonymous$$s was articulated clearly enough... I t$$anonymous$$nk I'm very close but somet$$anonymous$$ng is wrong with Quaternion.LookRotation... is there a better method I could use?

sample2.jpg (22.4 kB)
sample.jpg (46.2 kB)
Comment
DarkestAngel

People who like this

1 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 DarkestAngel · Jan 26, 2020 at 07:23 AM 0
Share

You may also try looking at using transform.localrotation instead of transform.rotation. Did you ever find a solution to your problem?

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by DarkestAngel · Jan 23, 2020 at 06:38 AM

Have you tried rotating your scene and camera instead of the character? Then you can rotate your character normally?

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

254 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 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

Cube Rotation Without Input 0 Answers

Why does the player not move around planet with gravity ? 1 Answer

How to make my sprite rotate to face the direction they are currently moving? (2D) 0 Answers

Rotate sphere to the direction of movement 0 Answers

Camera Follow Problem 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