Hey guys. I really didnt know how to make it clear in the title, so this is my problem. So basically I have a farm environment and a field adjusted to the x and z axis (3D scene). The field is surrounded by fences which are rigidbodies. Now I want to move my player in this field BUT I want him to move from his current position to the fence in his moving direction with only one keypress. That’s no problem. The problem is i want the player to be kinetic after he hit the fence. I cannot do a normal onCollision function because there is the opportunity that he is moving along the fence on one side which would trigger the onCollision function directly after the moving function has started. Then I had an idea. I should be able to detect at which point his velocity is below a given value because when he hits the fence, the velocity should automatically be less then it was before right? So I came up with this function. Problem is, it is not working^^
if (Input.GetKeyDown (KeyCode.RightArrow)&& moves > 0 && rigidbody.isKinematic == true){
rigidbody.isKinematic = false;
rigidbody.velocity = new Vector3(0, 0, -speed);
if (rigidbody.velocity.z > speed) {
rigidbody.isKinematic = true;
moves = moves - 1;
}
}
The rigidbody.velocity.z detection isnt working, so he character is stil moving a little along the fence, after he collided with it. Any ideas?