- Home /
Fire Knockback, Vectors, Directions
I want to code this:
Note: This is from top view. Sorry that fire center is not really in the center. Imagine that it is.
Well right now, I can detect when player enters the set fire. I need to know a few things now. Firstly, how can I find C point coordinates? And also, how to give this direction to my movement. I know Vector3 defines a point (x,y,z) in 3D but what type of variable I can store a direction?
I use C# and I don't have rigidbody on my player character. Movement is done with Character Controller.
Answer by robertbu · Jan 25, 2014 at 02:24 AM
First off, since you are using a CharacterController, you will need to use OnControllerColliderHit() to detect the hit. This callback has a ControllerColliderHit as a parameter. This stricture gives you the point of impact (i.e. C). So your code to calculate the move will be something like:
void OnControllerColliderHit(ControllerColliderHit hit) {
Vector3 dir = transform.position - hit.point;
dir.y = 0.0f; // May not be necessary;
Vector3 knockBack = dir.normalized * knockBackLength;
// Code to use or communicate vector goes here
}
I don't know what your character controller code looks like, so I cannot be more explicit about how you integrate this code. If you want immediate jump, you likely can just call CharacterController.Move().