- Home /
Substitute of collision
My game is FPS style game and I don't want to use collision for the bullet detection of enemy so I want to know a substitute of this script but without using a collision system:
function OnCollisionEnter(other : Collision){
if(other.transform.tag == "enemy"){
//Do something
}
}
Note: Maybe there are many ways to do it, I actually know some ways to do it, but the important thing here is find the object where it pass(e.g. other.transform.tag == "enemy" that means it do something only if the object tag is equal to enemy)
Know I try it with Raycast, not error but when I quit the collider it doesn't work, it seams Raycast only works for using collider. This is the script I use:
//this script is in the bullet
var moredamage = 1.0;
function Update(){
var hit : RaycastHit;
if(Physics.Raycast(transform.position,transform.forward,hit)){
if(hit.transform.tag == "enemy"){
Debug.Log("You shoot me");
hit.transform.SendMessage("CanDie",moredamage,SendMessageOptions.DontRequireReceiver);
}
}
}
any suggestion, comment or answer would be great.
Answer by AngryOldMan · Mar 14, 2011 at 03:14 AM
Use raycasting, it still uses a form of collision but not the same as a collider colliding with another collider at runtime. search unity3d raycast tutorial in google, there are plenty of useful results there too many to list here.
thanks, I already know about raycast but, it can be possible to ins$$anonymous$$d of layermask use tag?
better take a look around the web and find out http://forum.unity3d.com/threads/28962-Identifying-GameObject.Tag-through-raycasting here is somewhere to get you started, check out some answers tagged raycast and tag on this website also.
but it seams something happens, again I don't know why it doesn't work without having a collider any suggestion or answer that could me with this please?
Raycasts only can detect colliders. agains what you want to raycast? The visual $$anonymous$$esh is just visual. You have to use a collider to raycast against. Why don't you want to use a collider? you can mark the collider as trigger and you still can raycast it. A trigger don't disturb the physics.
He says "use primitives for colliders" not "dont use colliders!" The guy asking the question states that he is using a $$anonymous$$ESH collider. The guy answering states to use PRI$$anonymous$$ITIVE colliders (which is just the basic collider shapes like cube, sphere, etc) On another note just because someone says to do so in another post and it worked for that guy doesn't necessarily mean that is going to work for you. Alot of the question (the well asked and answered ones anyway) are specific to the questioner, most answers you will have to use as a GUIDE to help you solve your problems
Answer by Noah-1 · Mar 14, 2011 at 03:40 AM
I reccomend you OnTriggerEnter:
function OnTriggerEnter (other : Collider){
if(other.transform.tag == "enemy"){
//Do something
} }
Check the box of trigger on the collider of your tagged Object.
sorry, but what I actually want is don't have a collider on, I forgot to mention it :P