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 TheBasementNerd · Nov 19, 2014 at 09:48 AM · rotationcube

How do I make a cube roll on a set forward path without it deviating

I'm trying to make a cube roll forward without having it bump left and right by it's own spinning. So physics causes it to spin around as it rolls, but it doesn't deviate from the path of going straight forward, and then have it be able to go forward in different directions without path deviation, but still allowing for physics to make the cube spin and jump off the ground due to spinning

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 KulestarUK · Nov 19, 2014 at 09:54 AM 0
Share

Are your different directions always along an axis? $$anonymous$$g. along +ve x and -ve x?

avatar image TheBasementNerd · Nov 19, 2014 at 05:21 PM 0
Share

No, it'll be sorta like rolling a ball around, my only issue is that a cube has edges so those edges continually cause some annoying deviations

4 Replies

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

Answer by TheBasementNerd · Nov 20, 2014 at 11:19 PM

I figured out a method, I created a 'move point' with the cube that sits in front of it however many units away. This move point is stored in a variable in the cube's script, and I have it combined with another section of code that allows me to turn it so that it always stays a set distance away from the cube, then I take the forward input (whatever it is set to) and apply force from the cube's position to the move point, multiplied by whatever so it goes faster:

 var movePoint = Vector3.forward;
 var dir = movePoint-transform.position;

 function Update() {
     if ((Input.GetAxis("Forward"+playerNum) != 0)) {
         rigidbody.AddForce(-((movePoint-transform.position)*500)*Input.GetAxis("Forward"+playerNum));
     }
     
     if (Input.GetAxis("Sideways"+playerNum)) {
         dir = Quaternion.Euler(0,3*Input.GetAxis("Sideways"+playerNum),0) * dir;
     }

     dir.y = 1.48
     movePoint.x = dir.x + transform.position.x;
     movePoint.z = dir.z + transform.position.z;
 }


In my game the cube is scaled to 3, so 1.48 ends up being the center of the cube's height, so I keep the y on dir set to that so it can still bounce around naturally but doesn't travel up and down with the cube. Forward line motion isn't perfect, but it works great to steer a cube around

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 screenname_taken · Nov 19, 2014 at 10:33 AM

You could set up some layers for the physics so that the cube is colliding only with your floor. Then have a waypoint system (just some empty triggers) that the cube is set to look at. It'll rotate itself towards them and you'll just keep pushing it forward.

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 iz7749 · Nov 19, 2014 at 11:28 AM

You could use constant force in the direction you want and freeze the position under the constraints of the cubes rigidbody for the direction you don't want the cube to roll, play around with adding some relative force or torque in various directions and amounts to make the cube spin and bounce but because of the position constraint it will only roll in that direction. http://puu.sh/cWZMn/bf4ab38255.png Then i guess you could change that in code to alter what direction the cube rolls just remember to change the position constraint. probably not the best way to do it but should work for what you want sd you should be able to set up some triggers that when the cube hits it, changes the direction the cube rolls.

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 thomasfriday · Jul 10, 2021 at 03:32 PM

Here's a short Youtube video that covers exactly how to roll a cube on its edges: https://youtu.be/06rs3U2bpy8


rolling cube

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2d Movement Messes up when cube is rotatated 0 Answers

Rotation along edge of a cube around another cube as its planet 1 Answer

Make an object rotate instantly upon an event occuring in C# 1 Answer

Tumbling a cube 1 Answer

Walking on a cube 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