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
1
Question by DanJC · Apr 01, 2013 at 10:23 AM · physicsrigidbodyanglesurfaceslide

How can I slide a cube perfectly over a changing surface?

I've had a hunt around but can't find anything to answer exactly this.

Here, the rigidbody cube is trying to slide around inside a capsule mesh collider, but it's toppling over when it has hit one of the edges between polys:

alt text

I want it to simply keep sliding around perfectly, so when the leading base edge of the cube hits a new incline, it just keeps sliding on up it.

.alt text

The surface is a custom mesh, so could be anything.

I want this behaviour so that Unity's physics can sort out the cube's orientation, then I take the normal of the cube's base (and not the normal of the surfaces it is resting on).

Is there a non-fudge-it way to do this?

topple2.png (76.7 kB)
topple.png (21.9 kB)
Comment
Add comment · Show 3
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 whydoidoit · Apr 01, 2013 at 10:36 AM 0
Share

So hang on - how would you define it's base? Presumably the base would rest based on it's support at a number of points - you're going to have to work that out I imagine. Where it's resting...

avatar image DanJC · Apr 01, 2013 at 10:41 AM 0
Share

Oh, I forgot to mention it will be using rigidbodies.

It is resting on the surface as a cube normally would. But unlike reality, I don't want it to topple forward if it hits an incline. Rather, it just keeps sliding smoothly.

A bit hard to describe simple things without images. :/

avatar image DanJC · Apr 01, 2013 at 06:41 PM 0
Share

The mesh is literally just a capsule with the normals turned inside out so I can move around its inside. I made the capsule in Blender; a UV sphere with its middle edge loopjust extruded out into a longer capsule shape.

Is it normal that lots of our posts get cut?

Racing game, ok.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Loius · Apr 01, 2013 at 05:09 PM

I built this object in, of all things, LittleBigPlanet and, amazingly enough, it seems like the same strategy would work here. (O_O)

Each Update (or whatever):

 Move Cube along its forward.
 For each 'corner' which must remain grounded:
   If (or, dangerously, while) a raycast from (that Corner plus Cube-Up)
       to Cube-Down does not hit the current surface
     OR
   A raycast from Corner to Cube-Down hits the current surface, but only
       after an unacceptable distance:
     Choose a Pivot point (should be defined per Corner;
       using the center of Cube ends up showing some clipping)
     Rotate Cube around Pivot towards this Corner
 
   If (while) the raycast from (Corner plus Up) 
       to (Corner) hits the surface:
     Choose a pivot point and rotate *away* from this Corner
     
 

This might be very similar to Fattie's answer; you could use repulsion/attraction forces at the Corners instead of pivot points.

Comment
Add comment · Show 4 · 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 Fattie · Apr 01, 2013 at 05:14 PM 0
Share

Exactly !!

avatar image DanJC · Apr 01, 2013 at 06:59 PM 0
Share

So basically if a corner is airborn, rotate the cube so that it's not.

Not sure how to choose those pivot points; could be 3 corners off the ground. Also, what do you mean by "Cube-Up"? The cube's local height? Likewise with Cube-Down, and in line 12, "Up".

avatar image Loius · Apr 01, 2013 at 07:02 PM 0
Share

Yep.

Those are local directions. World-Up is Vector3.up, Cube-Up (Up) is cubeTransform.up

avatar image DanJC · Apr 05, 2013 at 08:21 AM 0
Share

I imagine that pivot point would simply be the edge that remains on the ground, or in some cases, the single corner that remains on the ground.

I haven't tried this approach yet though. Just writing that for any readers.

avatar image
0

Answer by hexagonius · Apr 01, 2013 at 11:13 AM

May this could work: you do not move the cube directly but handle a projector of some kind. Think of the bowl if it was a completely hollow sphere. Place a Gameobject in it's center of which you controller the rotation. Shoot 4 raycasts onto the innersurface of the bowl where they have the approximate distance of the cubes bottom corners from each other. Maybe by checking a 5th center raycast. Then get a plane through all the contactpoints and rotate and transform your cube about it. This would make the cube move nearly precise I guess.

Even if that's not what you had in mind it might help thinking about the problem another way.

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 Fattie · Apr 01, 2013 at 11:15 AM 0
Share

note that fortunately if it's an actual sphere, the solution is trivial - the cube just points towards the centre all the time. you can do it instantly in unity with "TrickHolder" as described above, fortunately

avatar image DanJC · Apr 01, 2013 at 05:11 PM 0
Share

Thanks for the thought but indeed, non-regular mesh.

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

14 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

Related Questions

Rigidbody Sphere slides around when rotating. 0 Answers

How to calculate the angle of a trajectory to hit the target 1 Answer

Keep Horizontal Momentum after Jump 2 Answers

Collision.impulse = 0 in OnCollisionStay Kinematic Static collision pair after Update 0 Answers

RigidBody2D Movement Stuttering 3 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