# How can I get back a hit?

I shoot down a raycast and I need to know how to get back the hit. I need to get back the hit and than get the normal of the hit so I can use the hit’s Vectors(x,y,z). How could I do this. This is the script that I have right now. I am trying to make an fps movement script that is controlled based on the characters normals.Thanks for any help! If you have any other better way to calculate the normals so I can use their Vectors than please do tell. And the commented out lines of code are just what I used for basic walking without things like jumping and running and other such things.

``````using System.Collections;

//
//THIS SCRIPT CONTROLS THE MOVEMENT OF THE PLAYER
//
[RequireComponent (typeof (Rigidbody))]
public class PlayerMovement : MonoBehaviour
{
//ALL OF THE PUBLIC VARIABLES
public float walkSpeed = 6.0f;
public float runSpeed = 12.0f;
public float jumpSpeed = 8.0f;

//ALL OF THE PRIVATE VARIABLES
private Vector3 moveDirection;
private float speed;

void Start ()
{
//speed = walkSpeed;
}
void Update ()
{
//moveDirection = new Vector3 (Input.GetAxisRaw ("Horizontal"),0, Input.GetAxisRaw ("Vertical")).normalized;

RaycastHit hit;
Physics.Raycast (transform.position, -Vector3.up, out hit);

if (Physics.Raycast (transform.position, -Vector3.up, out hit))
{
//RIGHT HERE WOULD BE THE HITS NORMAL VECTORS(X,Y,Z)
}
}
void FixedUpdate()
{
//rigidbody.MovePosition (rigidbody.position + transform.TransformDirection(moveDirection) * speed * Time.deltaTime);
}
}
``````

You use the RaycastHit struct to get the hit back. You made a reference for it there, and you gave it the ‘out’ parameter. That means that ‘hit’ variable is going to be filled with hit information after the Raycast function runs.

So, in your “//RIGHT HERE WOULD BE THE HITS NORMAL VECTORS(X,Y,Z)” part, you could use:

``````hit.normal
``````

To get the normal.

You also don’t need two Raycast functions there like you have. The one in the if condition will cast the ray and return if it hit or not. If it did hit, it will run the code where your comment is.