hi guys,
I'm having trouble in turning this script into a playmaker fsm, I just can't grasp the script at all. Could any of you guys have a look and see if you can make an fsm that does the same.
code:
using UnityEngine;
public class BallBouncer : MonoBehaviour
{
[SerializeField]
[Tooltip("Just for debugging, adds some velocity during OnEnable")]
private Vector3 initialVelocity;
[SerializeField]
private float minVelocity = 10f;
private Vector3 lastFrameVelocity;
private Rigidbody rb;
private void OnEnable()
{
rb = GetComponent<Rigidbody>();
rb.velocity = initialVelocity;
}
private void Update()
{
lastFrameVelocity = rb.velocity;
}
private void OnCollisionEnter(Collision collision)
{
Bounce(collision.contacts[0].normal);
}
private void Bounce(Vector3 collisionNormal)
{
var speed = lastFrameVelocity.magnitude;
var direction = Vector3.Reflect(lastFrameVelocity.normalized, collisionNormal);
Debug.Log("Out Direction: " + direction);
rb.velocity = direction * Mathf.Max(speed, minVelocity);
}
}
and the attachment has the project