- Home /
Creating false gravity for a ball
I have a ball moving through a tube filled with gravity defying twists and turns. I have an empty object sitting at the center of the ball. Every Update I `rigidbody.constantForce.relativeForce = child.transform * -10;` where child is the inner empty object applying this force to the ball to replicate gravity. The next step is to apply turning so the ball can roll around the inside of the tube so I have
if(Input.GetKeyDown("right")){
child.transform.Rotate(transform.forward * 10);
}
else if(Input.GetKeyDown("left")){
child.transform.Rotate(transform.forward * -10);
}
So the inner child will rotate, and "gravity" will be applied to its new down, so in theory the ball should be pulled where ever the inside is pointing away from. The ball should be able to stick to the ceiling. And initially it does. The problem is that whenever I try to rotate the ball does not just move and is along the new edge, it starts rocking and spinning and generally going crazy. Is there anyway to stop this spin out with out freezing the rotation, because it will have to roll down the tube?
Answer by ScroodgeM · Aug 25, 2012 at 08:44 PM
i'd try to imagine what you are actually doing with this line
child.transform.Rotate(transform.forward * -10);
but can't 8)
methinks you need something like
child.transform.Rotate(Vector3.up * -10);
Sorry I wish it were that easy, any i forgot to mention that the tube is along the z axis so this is the proper rotate. But here's a new little wrench it all of it, the ball starts rocking on its x axis even when i dont press anything.
transform.Rotate rotates around transform's self space by default. so check again does your row with this rotation correct
you can (and better do so) freeze unneeded rotations in rigidbody's settings
Yeah its doing the right rotations when it should, and I can't freeze any of the rotations because the tube is random so it might have to turn and any different direction, and the child is just an empty object so it doesn't have a rigidbody. What I think the problem is, is that the tube is an imported object so if I give it a collider, it wraps around the outside and not the inside, so the ball falls through part of the tube and then freaks out. Only I dont know how to fix that in maya or unity.
about collider: does the ball always should be inside a tube? if so, tube should have surface faced inside itself and mesh collider will work properly then.
about issue: need some explain about 'going crazy etc'. may be $$anonymous$$imal shared pack to reproduce issue?
The ball will always be inside the tube, and I tried adding a mesh collider but that's causing its own problems that I am trying to solve here: http://answers.unity3d.com/questions/308191/mesh-collider-maya-import.html the collider doesn't want to wrap on the inside.
Going crazy means that with out touching any buttons, the ball falls a bit(about and 8th) into the tube and starts rocking back and forth slowly but then it picks up and rolls around the tube in random directions and eventually just flys off into the void.
Your answer
![](https://koobas.hobune.stream/wayback/20220613080154im_/https://answers.unity.com/themes/thub/images/avi.jpg)