Fall down Cube object from platform.
Hello Unity Developers, I have a problem with 'rotation falls' of "Cube" object. The Cube object (as you can see on the picture) has a scale size (1.2.1). I want the cube falls down when it's half part on the air. I mean if cube's half part on the platform and other part on the air . There are empty objects with tag "Fall" and with collider (Trigger is checked). When my cube is EnterTriggers it must fall down from the platform. It's works only in sometimes but not always. I put Y Gravity -175 in Edit=>Project Settings=>Physics.
There is a code which must make my Cube falls down (outweigh).
`using UnityEngine; using System.Collections;
public class ObjectFallAway : MonoBehaviour {
public Rigidbody rb;
public AudioClip fail;
void Start ()
{
rb = GetComponent<Rigidbody>();
//rb.constraints = RigidbodyConstraints.FreezePosition;
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Fall")
{
gameObject.GetComponent<Roll>().enabled = false;
rb.constraints = RigidbodyConstraints.None;
StartCoroutine (Load());
}
}
IEnumerator Load ()
{
yield return new WaitForSeconds (0.5f);
//GameObject.Find("Map").GetComponent<AudioSource>().PlayOneShot (fail);
yield return new WaitForSeconds (3.0f);
Application.LoadLevel ("Island");
}
}
Is there a best way to solve my problem please? If I use Rigidbody.AddFore, can it help me? if yes please comment and give me please sample how to do it. Because I'm new in coding(( I only make simple codes. Thanks in advance.
Howdy, so I'm not sure I totally understand your problem. Are you saying that you'd like the cube on top to naturally fall off of the platform when moves over the edge? If so, that should happen normally. Perhaps you can explain in more detail what you really are trying to do?
Also, your gravity value is HUG$$anonymous$$ I would recommend setting it back to its default.
Thank you $$anonymous$$ike:) There is a link video which shows the (1.2.1) sized Cube falling down from the platform: https://www.dropbox.com/s/7lhv23bh2jq8n3j/Falling.mov?dl=0
I would like to have exactly such as falling in my game.
There is someone has commented on my FB post, but I know nothing and can't understand about Raycasting :( His answer: "you could do a little raycast going a little in down direction on each side of the cube, when your ray don't hit anything (this side of the cube is in the air) add a strong force downward (in global space) at this position of the cube. This way if your cube is ~50% mid air (taking in $$anonymous$$d that the center of balance is the center of the cube), the cube should fall easily. Else you could try to create a physics material with little drag."
If will only happen if the centre has gone past the edge of the cube below, and in some cases it won't have, as I assume the cubes are exactly half the size of the block.
You could try raycasting from each 'part' of the block, where the block would be 2 parts, each a cube. if you hit something, leave it alone, if one end doesn't hit anything, use AddForceAtPosition to push it down where it didn't hit the raycast.
Alternatively you could reduce your cubes to be the tiniest bit smaller than half your block, and it should work.
If neither of those work, how are you controlling the position and rotation, perhaps you are stopping it from moving naturally?
Raycasting sample will be great. I can't figure out what to write in code raycasting
Try this example to learn about raycasting: http://unity3d.com/learn/tutorials/modules/beginner/physics/raycasting?playlist=17120
Answer by Scribe · Sep 09, 2015 at 08:36 AM
If you are successfully triggering the 'Fall' collider, then you can make a simple change, instead of:
AddForce
try
AddForceAtPosition(-Vector3.up * hoverForce, other.transform.position+new Vector3(0, 0.5f, 0), ForceMode.Acceleration):