Hello,
Hope everyone is having a fantastic day so far!
I was hoping someone with experience is bored and could help me convert a script into states of an FSM? Currently the script works fine id just like to learn how to do it using actions. It's a small script and I'll keep trying if no one replies
and if I ever get it I'll post the answer here as well
If someone is kind enough to help it would be greatly appreciated!
public class Bullet : MonoBehaviour
{
public Transform bullet;
private float speed = 5;
void Update()
{
transform.Translate(Vector3.forward * Time.deltaTime * speed);
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Time.deltaTime * speed + .5f))
{
Vector3 reflectDir = Vector3.Reflect(ray.direction, hit.normal);
float rot = 90 - Mathf.Atan2(reflectDir.z, reflectDir.x) * Mathf.Rad2Deg;
transform.eulerAngles = new Vector3(0, rot, 0);
}
}
}
Background: There is a sphere in the scene (as my bullet) and a cube (as the wall) if the sphere hits the wall head on it will ricochet straight back. If the sphere is on an angle it would bounce off the wall at an angle which is pretty sweet.