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 4ndro1d · Nov 19, 2013 at 11:14 AM · cameracuberoll

Move a cube on it's edges

Hey guys,

I'm trying to move a cube on a grid. So one move should look like an animation , where either x or y values are changed by +/- 1 and a rotation of 90 degree.

alt text

Anyway I couldn't find a good solution on this. I read something about animations, but I'm not sure if that's what I need and how I could differ between the directions.

Are there any ideas on this?

Additionally I couldn't fix my camera to my object yet (always above). I can't make the camera a child of my cube, because the cube is instantiated in code.

Any ideas on this?

unbenannt.png (24.5 kB)
Comment
Add comment
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

2 Replies

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

Answer by gajdot · Nov 19, 2013 at 11:47 AM

First of all you need a follow script attached to the camera. Something like this:

 camera.transform.position = new Vector3(target.transform.x, target.transform.y+5, target.tranform.z);

Something like this in the update function, to track the position of your cube.

Now about the rotation I need to think a bit and I have work atm. It needs to be done or adding torque or animation or just rotating an object, but I need to test which works best. When I get home I'll try it out for you and post my results.

Comment
Add comment · Show 8 · 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 4ndro1d · Nov 19, 2013 at 03:41 PM 0
Share

The problem with this attempt is, that I also instantiate the Cube in my code. So in the Scene there is nothing but the camera.

I now did an animation for my cube to move on key input. The problem i am facing now, is that the animation will always reset the object to the animations origin. How could I achieve it to be relative?

avatar image gajdot · Nov 19, 2013 at 04:15 PM 0
Share

Well one hack you could do is that, you can translate your object as soon as your animation stops to the new location, so it would seem it will remain there.

avatar image 4ndro1d · Nov 19, 2013 at 04:24 PM 0
Share

That's what I already tried to do, I guess animation.Play("move_forward", Play$$anonymous$$ode.StopAll); transform.Translate(Vector3.forward, Space.World); But I recorded my animation at 0,0,0. Although I Instantiate my cube at 5, 0, 5 it will jump to the origin at start of the animation. Also the cube will not be positioned as it would without the animation

avatar image gajdot · Nov 19, 2013 at 04:40 PM 0
Share

I see, the problem is that you need a parent object positioning your cube with this solution. You would need a parent emptyGameobject witch would be the cube holder and record the animation on the children of this object witch would be your cube. This way if you position your parent it will bring your cube with it and use it's local origin. Try this or if you want I just arrived home and I can write you a functional script to rotate it, without animation.

avatar image 4ndro1d · Nov 19, 2013 at 05:16 PM 0
Share

I already tried this approach but I failed. But I also don't want to to put too much time in my project. I guess I will have to mention you in the credits ^^

Show more comments
avatar image
0

Answer by tanoshimi · Nov 19, 2013 at 11:56 AM

Two ideas (both untested) to roll the cube:

  1. Use transform.RotateAround, choosing the pivot point to be the centre of the edge lying on the floor in the direction you want to roll the cube (which should be relatively easy to find given you know the cube's dimensions and it's centre point).

  2. Use Physics, giving the cube a material that is very high friction, high drag, and low bounce. Then apply a force to the cube - it should roll over rather than slide.

Comment
Add comment · Show 2 · 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 4ndro1d · Nov 19, 2013 at 01:33 PM 0
Share

Hey, but do I have to know in which direction the cube currently is heading? Because if this is the case it sounds quite complicated to me.

Let's say I want to add the logic for rotating here:

 if(Input.Get$$anonymous$$eyDown("w")){
         transform.Translate(Vector3.forward, Space.World);
         }

I also do not know how to apply a force according to my movement.

avatar image tanoshimi · Nov 19, 2013 at 01:51 PM 0
Share

No you don't need to know which way the cube is "pointing" because it's a cube so it makes no difference - it's completely symmetric in all its movement axes. You only need to know which direction you want to push it in (e.g Vector3.Forward, Vector4.Right, -Vector3.Forward or -Vector3.Right). Calculate the pivot point from cube centre + width/2 translation in x/z axes (to find the "side" on which to rotate, - height/2 (to get the point in the middle of the bottom edge of that side)

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

19 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

Related Questions

Setting a cube to be exactly size of intersecting camera view plane 1 Answer

Roll a cube help 0 Answers

How to make camera position relative to a specific target. 1 Answer

How to lock camera roll in C# 1 Answer

How to make a "pressure sensor" of sorts that when rolled over switches to another scene 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