Confused on 'Is Trigger' on a Sphere Collider

194 views
Skip to first unread message

Paul

unread,
Sep 28, 2012, 6:13:49 AM9/28/12
to unity3d...@googlegroups.com
Hi All,
 
I'm very new to Unity and just playing around with it, trying to get a feel for the software. I have designed a very simple (so far) scene where I basically have a walled garden with a Sphere moving around inside. This is constantly moving forward and you control direction using left-right arrow keys. The main camera does a smooth follow and it's all working fine. However if I select the 'Is Trigger' check box on the sphere, the left-right controls suddenlt become very lethargic. My Turnspeed which is normally set at 10 has to be 100 to get the same effect as when the 'Is Trigger' is off. Am very curious as to why this may be?
 
This is the code in the PlayerController script (very simple stuff)
 
void Update()
{
   rigidbody.AddTorque(0, Input.GetAxis("Horizontal") * TurnSpeed * Time.deltaTime, 0);
   rigidbody.AddRelativeForce(0F, 0F,  MovementSpeed );
}
 
thanks
Paul
 

Paul Conway

unread,
Sep 28, 2012, 6:45:26 AM9/28/12
to unity3d...@googlegroups.com
Hi Paul, why are you setting the sphere (player?) to isTrigger? What are you trying to achieve? If you want to trigger certain events at points, drop down shapes with colliders and set them to isTrigger. Make sure the player sphere has it's tag set to "Player". The player sphere should also have a character controller. Write up this function and place the script on the new shape collider. Hope this helps!

void OnTriggerEnter (Collider other) 
 {
    if (other.tag = "Player")
   {
   Debug.Log ("Player has set off trigger!!");   //Check your console log to see if this message pops up when you the player touches the trigger, if it does, then yay, it works!
   //Do something interesting
   }
}




Paul Conway
------------------------
Level Designer
bitSmithgames.com

Paul

unread,
Sep 28, 2012, 6:55:11 AM9/28/12
to unity3d...@googlegroups.com
Hi Paul
 
Thanks for that, setting the player to trigger was accidental, plan is as you suggest. However my curiosity has been raised now and I'd like to find out what the reason is :)
 
 

Mark Aherne

unread,
Sep 28, 2012, 7:08:32 AM9/28/12
to unity3d...@googlegroups.com
A Collider set to isTrigger no longer collides with other colliders (including terrain), this is probably what's affecting the handling of the sphere.

So a Collider with isTrigger set to false is a physical object in the simulation. See OnCollisionEnterOnCollisionExit and OnCollisionStay. You can use these three methods to handle your sphere collisions.

A Collider with isTrigger set to true is not a physical object in the simulation (it won't interact with other colliders), it only generates collision events. See OnTriggerEnter, OnTriggerExit and OnTriggerStay.

Also AddRelativeForce adds force along the object's axis, not the world axis, so if the sphere is rotating along the X axis that's going to be an issue too.


Hope that helps,

Mark

Paul

unread,
Sep 28, 2012, 3:39:05 PM9/28/12
to unity3d...@googlegroups.com
Thanks Mark, that does make some sense, but still not very clear. The way that collision detection is handled shouldn't really effect movement I would have thought. Either way it's just a curiousity
 
Paul.
 
 

Sameer Anghan

unread,
Mar 18, 2014, 2:42:48 AM3/18/14
to unity3d...@googlegroups.com
ThanX, Mark Aherne, proper answer.
Reply all
Reply to author
Forward
0 new messages