Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 moldywood · Nov 25, 2017 at 06:46 PM · physicsrigidbodygravityaddforcerigidbody.addforce

How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce]

I have a world cube (as opposed to a sphere), and on each of the six sides i have rigidbodies that need to fall towards it's relative side/ground. ConstantForce's Force parameter won't work because the world cube will need to rotate, and when that rotates, all the rigidbodies global rotation axis also changes. The Relative Force parameter won't work either because the rigidbodies themselves can also rotate independently, so their local rotation axis can change.


So i figure some type of script that runs AddForce and adjusts the vector based on position and rotation of the rigidbody in relation to it's side would be the solution. I've posted in the forums about it (forum post) but haven't received any replies.


My current solution works but i feel there must be a better way. You can find my current unity project at my Github with the scene set up with the cubes, but i'll also post the script here. The rigidbody must be child to the collider surface/ground/side it should fall down towards.


rigidbody using System.Collections; using System.Collections.Generic; using UnityEngine;

 [RequireComponent(typeof(Rigidbody))]
 public class gravityBody : MonoBehaviour {
 
     public float gravity = -10f;
     Rigidbody rb;
 
     void Start () {
 
         rb = GetComponent<Rigidbody> ();
         rb.useGravity = false;
         
     }
 
     void FixedUpdate () {
     
         rb.AddForce(rb.transform.parent.up * gravity);
 
         //rb.AddRelativeTorque(new Vector3(0f,-0.25f,0f));
 
     }
 }

thank you.

Comment
Add comment · Show 4
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 nt314p · Dec 04, 2017 at 01:16 AM 0
Share

To clarify, you want them to fall down on the faces?

For example even if the object was close to the corner, it wouldn't slide/fall toward the center of the face?

avatar image moldywood nt314p · Dec 04, 2017 at 06:34 AM 0
Share

Correct, it should fall straight down. So my current solution, since the object can potentially rotate and change it's local y axis, is it uses its parent's (the ground beneath it) local y axis. The ground beneath it never independently rotates, so the Y axis well stay the same (going straight through the "world cube" origin).

avatar image nt314p moldywood · Dec 06, 2017 at 02:20 AM 0
Share

So what does your script do so far?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

140 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

add force to object that has 2 different rigid bodies 0 Answers

Rigidbody.velocity seems to be breaking jumping physics 0 Answers

How can I match Unity's gravity implementation per object? 1 Answer

Physics in 2D mode not working? 0 Answers

Setting a RigidBody's velocity messes with my custom gravity, not sure how to proceed. 0 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