Raycast distance affected by momentum of character

Hello all,

basically I’m working on a fighting game, and I’m using a raycast from the player position forward at given punch distance to test for a hit. I’m using controller.SimpleMove for movement. Everything seems to work right if I’m standing still, but if I’m walking toward the other character, punches will land from far, far away (and even then the hit.distance is extremely low). Here’s the relevant code:

function ApplyPunch(punchType : punch)
{
var hit : RaycastHit;
var fwd = transform.TransformDirection (Vector3.forward);
var pos = transform.position;
var distance = punchType.distance;

if (Physics.Raycast (pos, fwd, hit, distance)) {

etc....

If I’m standing right in front of the other guy, hit.distance is about .5, but if I’m moving toward him, even from all the way across the scene, it’s about .02. So I guess the question is, how can I get my raycast to ignore the momentum of my character? None of the variables being passed in (as shown above) change when I’m moving, so I just can’t figure out why this is happening. Thanks in advance to anyone with suggestions…

Are you sure that your ray cast is hitting the other guy, and not the character that is shooting it? Such a short distance would suggest something like that. You should make sure that the ray cast ignores the originating character. Perhaps something like this:

http://forum.unity3d.com/threads/37900-Raycast-quot-Ignore-quot-Layers