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 Archonn · Sep 21, 2012 at 07:16 PM · animationcuberoll

Rolling a cube

After creating a animation with unity with keyframes etc, is there anyway to write code to edit the precise coordinates of the keyframes so that the coordinates can be changed at runtime.

More precisely, i want to create a cube which rolls in different directions 1 cube distance at a time whenever the user presses up down left or right. If not by editing keyframes like i described, how should I go about it?

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 DaveA · Sep 21, 2012 at 10:18 PM 0
Share

Animations would work best only if the cube is the same color on all sides, no texture that can be oriented visually.

avatar image DaveA · Sep 22, 2012 at 02:37 AM 0
Share

Reopened. Yes, it's been asked and answered and a simple search on Archonn's part would have show it, but it was asked by others, and we have SOO many re-asked questions, to start trying to police them all seems daunting. I may be wrong, feel free to overrule.

2 Replies

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

Answer by Fattie · Sep 22, 2012 at 06:16 AM

FYI it's remarkably simple to "roll" a cube around in unity, physically. just ensure you are using absolutely realistic sizes, masses and physic-materials, for both the cube and the surface.

and then just apply forces to it, or perhaps torque, at the correct points.

the question is identical to the question "how to roll a 5cm cube around on my kitchen table?"

how would you do that? think about where you'd tap it with your finger, how hard, what sort of material you'd need to make it work best, and so on.

If you want to animate it, as DaveA. says just use RotateAround...

start at the center of the cube. go down one half cube width. now go in the direction you want to travel one half cube width. that's the point to use in RotateAround. make a vector that points to the left of the direction you want to go and that's the axis to use in RotateAround. (if you struggle with getting the "left" each time, just manually make a trivial array of four vectors being the relevant four "leftwards" hinge directions for the four directions you'll want to travel, then you can use that throughout.)

i suppose it's just

 rotatearound(
 center + desired x halflength + vector3.down x halflength,
 Vector3.Cross(desired,Vector3.up),
 90
 )
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
1

Answer by DaveA · Sep 21, 2012 at 10:20 PM

As a coder I usually first think how I would do this in code. FWIW: Given the direction you want to move, find the edge on the ground that would be the pivot, and use RotateAround to do the movement.

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

12 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

Related Questions

Mechanim Eliminates Gravity 0 Answers

Move cube forward 0 Answers

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

Moving a Cube 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