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 Avadora · Sep 06, 2018 at 01:29 AM · rotationmovementrigidbodyworldspaceconstraints

Is it possible to constrain an object's rotation in worldspace?

I'm a beginner.

My player is a cube that moves by rotating 90 degrees on an axis (so if I constrained y rotation in inspector, it would disable part of my movement). If I change directions too soon before the rotation is finished, it has a tendency to rotate very slightly on the y axis, so that now when I move forward or back, I'm no longer parallel with the tiles I'm moving across.

Thanks in advance for any help you can offer.

Comment
Add comment · 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 JVene · Sep 06, 2018 at 02:40 AM 0
Share

We'll need to see code that's doing what you describe to be of much help.

2 Replies

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

Answer by peaceofmind1188 · Sep 06, 2018 at 04:48 AM

You can write the code so that every time the forward or back button is pressed down the rotation is set to exactly 90 degrees.

Keep at it! I just solo developed my first app and it's now on Itunes and Android! It's called Microbz!

https://itunes.apple.com/us/app/microbz/id1418937151?ls=1&mt=8 https://play.google.com/store/apps/details?id=com.peaceofmindgames.microbz

I hope my suggestion works and I hope you get a chance to try my game =)

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 peaceofmind1188 · Sep 09, 2018 at 04:44 AM 0
Share

If you want more insight on complete game development, I am doing a step by step process on Instagram at https://www.instagram.com/peaceof$$anonymous$$d_games/

Also, holding a live session 09/11/2018 at 7:00P$$anonymous$$ PST at https://ga$$anonymous$$gama.amafeed.com/how-to-create-a-game-with-zero-experience-ask-me-841927

avatar image
0

Answer by Koyemsi · Sep 06, 2018 at 04:13 AM

Maybe the player input should be disabled before the rotation is complete ?

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 Avadora · Sep 06, 2018 at 04:34 AM 0
Share

I found this script online and copy/pasted it. I've read through and have a general understanding of how it works.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Player$$anonymous$$ovement : $$anonymous$$onoBehaviour { public float speed; // The point the cube will rotate around // They represent the middle point of each 4 bottom edges of the cube Vector3 forwardRotationPoint; Vector3 backRotationPoint; Vector3 leftRotationPoint; Vector3 rightRotationPoint; Bounds bounds; bool rolling;

 void Start()
 {
     bounds = GetComponent<$$anonymous$$eshRenderer>().bounds;
     // Compute the rotation points
     forwardRotationPoint = new Vector3(0, -bounds.extents.y, bounds.extents.z);
     backRotationPoint = new Vector3(0, -bounds.extents.y, -bounds.extents.z);
     leftRotationPoint = new Vector3(-bounds.extents.x, -bounds.extents.y, 0);
     rightRotationPoint = new Vector3(bounds.extents.x, -bounds.extents.y, 0);
 }

 void Update()
 {
     // $$anonymous$$ake sure you are not already rolling / moving
     if (rolling)
         return;

     // Rotate around forward point when pressing the up button
     if (Input.Get$$anonymous$$ey("w"))
         StartCoroutine(Roll(forwardRotationPoint));
     // Rotate around back point when pressing the down button
     else if (Input.Get$$anonymous$$ey("s"))
         StartCoroutine(Roll(backRotationPoint));
     // Rotate around left point when pressing the left button
     else if (Input.Get$$anonymous$$ey("a"))
         StartCoroutine(Roll(leftRotationPoint));
     // Rotate around right point when pressing the right button
     else if (Input.Get$$anonymous$$ey("d"))
         StartCoroutine(Roll(rightRotationPoint));
 }

 // $$anonymous$$ake the cube roll around given rotation point
 private IEnumerator Roll(Vector3 rotationPoint)
 {
     // Compute the real rotation point according to current position
     Vector3 point = transform.position + rotationPoint;
     // Compute an axis to rotate in the correct direction
     Vector3 axis = Vector3.Cross(Vector3.up, rotationPoint).normalized;
     float angle = 90;
     float a = 0;
     // Prevent the user from rolling since we already are
     rolling = true;

     while (angle > 0)
     {
         // Compute the angle and rotate the cube around the point
         a = Time.deltaTime * speed;
         transform.RotateAround(point, axis, a);
         // $$anonymous$$eep track of the remaining angle
         angle -= a;
         yield return null;
     }
     // Adjust the rotation to make sure the cube rotates **exactly** 90°
     transform.RotateAround(point, axis, angle);

     // Allow the user to roll in a new direction
     rolling = false;
 }

}

I think the rolling bool is to disable movement while it's going, but I'm not sure what I might change to extend the window of time that player controls are disabled.

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

183 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

Related Questions

Player model Rigidbody keeps falling upsidedown 0 Answers

How to make a RigidBody not go into ground when tilted foward? 2 Answers

Stop A player Turning at Specific Point. 1 Answer

Rigidbody constraints not working with parent/child relationship 2 Answers

How does one constrain rotations of a CharacterController without a Rigidbody? 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