• 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 this is a silly question, I'm pretty new to unity but have been trying to figure this one out all day..

So I'm making a test scene for a game with orthographic, 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 achieve the proper perspective, which 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 this easily by parenting it to an Empty Game Object, which 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 this misaligned z-axis of the child model and not the parent. To achieve this, 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 Child 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);
             }
     

This 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 this was articulated clearly enough... I think I'm very close but something 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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

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

Why does RotateTowards rotate in an "orbit" rather than on the spot? Help me understand! 0 Answers

My Prefab goes crazy and it moves faster when i click in another thing of the unity editor or the scene even if that didn't suppose to happen 0 Answers

How to move my rigid body in the direction my model is facing. 0 Answers

Question about rotating an object thats moving. 1 Answer

Smooth Rotation on WASD keys pressed? 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