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 /
  • Help Room /
avatar image
0
Question by jannaisop · Mar 16, 2017 at 04:33 AM · rotationphysicsquaterniongridcube

Move an object around all 6 sides of a cube

For the past couple of days I've been experimenting with different ways to move one smaller cube around a big cube. Each method I've tried seems to work but not perfectly as there are bugs or other problems with the solution. I'll attach a few photos to show you what I'm trying to achieve. It's a 3D snake game where the player moves around a cube.

alt text

I've tried three different things each with not the best results. So to start off with I'm just using a basic movement script to move the cube around.

 void playerMovement(){
 
         player.transform.Translate (Vector3.forward * (Time.deltaTime * speed));
 
         if (Input.GetKeyDown ("left")) {
             player.transform.Rotate (0, -90, 0);
         }
         
         if (Input.GetKeyDown ("right")) {
             player.transform.Rotate (0, 90, 0);
         }
     }

So the first thing I tried was using box colliders with triggers set on the edges to rotate the player 90 degrees. This presented two problems. The first problem being that I needed two triggers on each edge and this would make the player cube rotate inside in the bigger cube. So I added a wait timer before you could rotate again. This worked but now if the player moves around the edges and stays in contact with the cube once he exits either side it will rotate the player cube inside the bigger cube again. alt text

     IEnumerator waitForExit(){
         yield return new WaitForSeconds (1.5f);
         player.GetComponent<movement>().canRotate = true;
     }
 
     void OnTriggerExit(Collider other) {
         if (player.GetComponent<movement>().canRotate == true) {
             other.gameObject.transform.Rotate (90, 0, 0);
             player.GetComponent<movement>().canRotate = false;
             player.GetComponent<movement> ().disableTurn = false;
             StartCoroutine (waitForExit ());
         }
 
     }

So the last thing I tried was using a downwards force on the cube that would make the cube stick to the surface no matter what side it was on. But this presented an issue where when the cube tipped over the edge it would bounce and throw off the rotation slightly. Even with a freezed rotation it would still give the same result.

     void FixedUpdate(){
         rb.AddForce(-transform.up * gravity);
     }




So this is where I'm stuck at. I'm still trying to find the best method to achieve the desired results. I've looked at methods that use gravity on spherical objects but this doesn't seem like what I need either. I've looked into a pivot point method or raycasting but wouldn't know where to start with those. Any methods or a fix to methods above which you can think of that would help would be greatly appreciated.

triggers.png (6.2 kB)
basicdiagram.png (9.6 kB)
Comment
Add comment · Show 2
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 hexagonius · Mar 16, 2017 at 09:16 AM 1
Share

here is another idea. you know the dimensions of the cube exactly. that means, you know if the next step goes off edge or not. that means, with a little vector math you should be able to turn your cube in an instant around the edges. using the dot product you could even split the moment into rotation around the edge axis and moment along the axis to make the character rotate amount the edges. this will get hard on the outer corners though.

avatar image jannaisop hexagonius · Mar 16, 2017 at 10:09 AM 0
Share

Thanks hexagonius for the idea. Using your suggested idea I clamped the X, Y and Z values of the player cube transform to the dimensions of the bigger cube. Once the player cube reached lowest or highest clamped values I rotated the player cube 90 degrees. I'll take a look into using a dot product as the idea of a smooth rotation sounds nice :)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by PSpiroz · Mar 16, 2017 at 10:44 AM

alt text

???

Did not quit get the original problem. I think you expose us your solution's problems.


proposal.jpg (25.4 kB)
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
avatar image
0

Answer by mona_alaa · Oct 23, 2018 at 05:41 AM

@ jannaisop Did you find a solution for this ?

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

134 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

Related Questions

Player rotates spastically on all axes when camera is turned 0 Answers

How to know whether the two object parallel intersected or perpendicularly intersected ?? 0 Answers

Quaternion relative difference problem 0 Answers

Keep Rigidbody upright using torque. 1 Answer

Determining if my target is standing upright 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