I have a cube and a terrain in which the cube is moving away from the terrain at a regular pace . what i need is to enable gravity for any object that comes in between both of the objects(terrain & cube),much like an extensible collider .Is there any way to implement this using colliders or other stuff.thanks in advance.
You can use a CapsuleCastAll.
[CapsuleCastAll][1]
Essentially, it’s a Capsulecast that stores all colliders within the Cast in an array. So you’ll have to call it every update and specify where it starts and ends. Like so:
//Get distance of cube from floor
var distance : float = Vector3.Distance(cube.position,floor.position);
var hits : RaycastHit[];
hits = Physics.CapsuleCastAll (cube.position, cube.down * distance, 1.0, cube.down, distance);
for (var i = 0; i < hits.Length; i++) {
//Apply Gravity;
hits_.rigidbody.AddForce(Vector3.down * Physics.gravity);_