Hey everyone,
I followed a tutorial on how to create Tracer’s blink ability from Overwatch, where the player moves forward a certain distance while using a Raycast to detect collisions so they don’t blink through walls. All was well when I tested it on a Cube, however as soon as I attached it to my player GameObject it didn’t budge. While trying to figure out what the issue was I disabled the Character Controller component on the Player and I was able to blink properly however I couldn’t move my character using the movement keys. Any help would be appreciated.
Thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Blink : MonoBehaviour
{
public int amount = 3;
void Start()
{
StartCoroutine("Reload");
}
void Update()
{ if (amount != 0)
{
if (Input.GetMouseButtonDown(1))
{
Vector3 ray = transform.TransformDirection(Vector3.forward);
RaycastHit hit;
if (Physics.Raycast(this.transform.position, ray, out hit, 10))
{
this.transform.position = hit.point -= this.transform.forward * 1;
}
else
{
this.transform.position += this.transform.forward * 10;
}
amount -= 1;
}
}
}
IEnumerator Reload()
{
yield return new WaitForSeconds(3);
if(amount < 3)
{
amount += 1;
}
StartCoroutine("Reload");
}
}