- Home /
Question by
jagjit777 · Mar 31, 2013 at 10:19 AM ·
collisiongameobjectrigidbody
why my object is sometimes going through walls ?
hello fiends, i have a cube that is constantly moving, whenever my cube collides with an object tagged "Wall",it should change its rotation and move in different direction,it is working fine but sometimes it gets problem in corners where 2 walls are intersecting eachother,the cube sometimes goes through walls....it have attached a pic that explains my problem very well.
var walkingSpeed : float = 10;
function Update ()
{
transform.Translate(transform.forward * walkingSpeed * Time.deltaTime,Space.self);
}
function OnTriggerEnter (otherObject : Collider)
{
if(otherObject.transform.tag == "Wall")
{
var rotationAngle = Array(90,180,270);
var newAngle = rotationAngle[Random.Range(0,rotationAngle.length)];
transform.eulerAngles.y = newAngle;
}
}
my problem.jpg
(56.9 kB)
Comment
Best Answer
Answer by whydoidoit · Mar 31, 2013 at 10:20 AM
It can choose an angle that takes it through the wall - you would need to detect which wall it was (tag, name whatever) and then apply an angle that is appropriate for that wall collision.
yes thanks thats a good idea...:) i appreciate your reply..thanks very much
Would be great if you could tick the question as answered