c# - How to allow an object to move within a collider? -


i trying have block can pushed inside of rectangular collider. player has able move through collider in order push block. have tried affect mass upon block being pushed edge collider, drag, angular drag, velocity, iskinematic nothing stop cube moving when hits collider. confusing, appreciated...here code:

public class pushblock2 : monobehaviour {      public rigidbody2d pblock2;       void ontriggerenter2d(collider2d col)     {         if (col.tag == "edge") {             debug.log ("pushblock2 touched edge");             pblock2.iskinematic = true;             pblock2.iskinematic = false;         }     }     void ontriggerstay2d(collider2d col)     {         if (col.tag == "edge") {             pblock2.iskinematic = true;         }     } 

why don't try , create 4 colliders around area want move block within? way you'll have stop block entering easier task trying prevent item leaving collider.

i pretty sure able pull off without code @ all, need setup couple of static colliders collide objects on layer , put cube wanna move on layer.

more info on layer-based collisions can found here: http://docs.unity3d.com/manual/layerbasedcollision.html


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -