Vector3.Reflect troubles

Hey.

So I’ve done some snooping around and I still can’t wrap my head around how this works, or even if it will work with what I’ve got.

I’ll try to be simple about this. I have a player, the player is controlled by a thumbstick UI so it’s movement looks like this;

transform.Translate(playerSpeed * Time.deltaTime * joy.AxisX, playerSpeed * Time.deltaTime * joy.AxisY, 0.0f);

When it his this ball, I simply pass that information to the ball and the ball shoots off in the direction the player hit it.

So the movement for the ball code looks like this;

transform.Translate(speed * Time.deltaTime * axisX, speed * Time.deltaTime * axisY, 0.0f);

So here’s my questions with regard to Vector3.Reflect;

  • is it even going to work with how I move this object? Or does it rely on my moving the object “forward”?
  • the API description is a bit confusing. link text And as such, I’m still confused as to what object’s transform goes into which slot! I’m hoping for an explanation that’s a bit easier to understand.

So for anyone who runs into this issue in the future, I did some snooping.

My main issue was I had “isTrigger” set to true on one of the objects. This is wrong. It needs to be off for OnCollisionEnter to detect it. (which you need to do)

Moving the object the way I was, had no effect on the ball for the function Vector3.Reflect.

After grabbing the collision point normal, and applying it to the Reflect function, I used the Vector3 that was given back to me as the ball’s new velocity. And it worked perfectly.

So the code looks like this;

if (coll.collider.tag == "Spin")
	{
		isMoving = false; //ignore this, it's for something else
		var hit = coll.contacts[0]; // grabs the first contact point
    	velocity = Vector3.Reflect(velocity, hit.normal); // new veloctiy = Vector3.Reflect (old velocity, point of contact.normal of point of contact)
    }
}