Im casting a ray and it stops working after it hits one time. I know Player1IsOnTop is set to true. Any help would be wonderful thank you.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player1Ray : MonoBehaviour
{
private Rigidbody rb;
public Animator animatorController;
// Start is called before the first frame update
void Start()
{
GameObject.FindWithTag("Player2");
rb = GetComponent<Rigidbody>();
GameObject.Find("Player2");
}
void FixedUpdate()
{
if (gameObject.GetComponent<PlayerMove>().Player1IsOnTop == true)
{
RaycastHit hit;
float distance;
Vector3 forward = transform.TransformDirection(Vector3.forward) * .00010f;
Debug.DrawRay(transform.position, forward, Color.green);
if (Physics.Raycast(transform.position, (forward), out hit))
{
distance = hit.distance;
print(distance + "" + hit.collider.gameObject.name);
if (hit.collider.gameObject.tag == "Player2")
{
rb.AddForce(transform.up * 25f);
if (animatorController)
{
animatorController.SetBool("Jumping", true);
}
else animatorController.SetBool("Jumping", false);
}
}