- Home /
Lerpz tutorial problems
Hi guys, firstly I'm a new kid around here. Well met.
Now for the questions, I've got a few questions about the Lerpz / 3D Platformer Tutorial. Currently I'm on the Adversaries chapter. I'm experiencing this problem. BTW, I'm using the newest Unity v 3.5, maybe it has something to do with my problem.
The laser game objects can't do a collision at all. I've done all the necessary steps like the one in the tutorial's pdf. I even added a Debug.Log in the "if (hit.collider.tag == "Player" || hit.collider.tag == "Enemy")" block. But they didn't get triggered at all. But if I put the Debug.Log at the first line in the Update() function it got called, so the script itself is working. What did I do wrong here?
Thanks in advance...
Show how your script looks. Right now you are talking about Update working and collision non-working, I suspect you are using the second in the first one. Collision functions are callbacks, they need to be set outside the Update.
Well, this is the script:
function Update () { var offset = (1 + $$anonymous$$athf.Sin(Time.time speed + ti$$anonymous$$gOffset)) height / 2; transform.position = originalPosition + Vector3(0, offset, 0);
//Debug.Log("LaserTrap: Update() ");
if (Time.time > lastHitTime + 0.25 && Physics.Raycast(transform.position, transform.forward, hit, laserWidth))
{
Debug.Log("LaserTrap: Hitting = " + hit.collider.tag); <-- added just now
if (hit.collider.tag == "Player" || hit.collider.tag == "Enemy")
{
Instantiate(hitEffect, hit.point, Quaternion.identity);
hit.collider.Send$$anonymous$$essage("ApplyDamage", damage, Send$$anonymous$$essageOptions.DontRequireReceiver);
lastHitTime = Time.time;
Debug.Log("LaserTrap: Object hit = " + hit.collider.tag);
}
}
}
As you can see, the I've added another debug log because I suspected that the raycasting worked but it didn't recognize the tag. And my suspicion is correct. I got lots of: "LaserTrap: Hitting = Untagged" lines in the console. And as a matter of fact, I haven't tagged the Lerpz with a "Player" tag. $$anonymous$$y bad. :P
Thanks for the answer. :D
PS: How do you post codes here?
Answer by bawenang · May 07, 2012 at 05:03 AM
Ok, the problem is solved. I've forgotten to tag the player so everytime the laser hits the player, it is recognized as "Untagged". A little tips here for the tutorial's document, maybe you guys should added that the developer trying this tutorial should re-check again for the tag of the player. Thanks.
Answer by amirabiri · May 04, 2012 at 10:36 AM
When I did the Lerpz tutorial it was out of date, it was built for Unity 2.x and I was using 3.0 at the time. But perhaps Unity have updated it since then.
Off the top of my head I would say: place a debug statement outside any ifs in the collision callback, check your tags, check the name of the callback against the API reference, and most importantly double check the origin and direction of the ray cast. The latter you can visually inspect when you run the game in the editor by using Debug.DrawLine, but you have to have Gizmos turned on in game view (upper right).
Welcome to Unity :-)
Thank you. Nice to meet you.
Like what I've said on the post above, I've stupidly forgotten to tag the player. So the raycast was detecting it as untagged. Sorry for the false alarm.
Thanks for the answer tho. :D