playMaker

Author Topic: help turning script into playmaker fsm [SOLVED]  (Read 731 times)

cel

  • Junior Playmaker
  • **
  • Posts: 96
    • View Profile
help turning script into playmaker fsm [SOLVED]
« on: February 01, 2018, 07:24:59 AM »
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:
Code: [Select]
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
« Last Edit: February 05, 2018, 03:23:42 PM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4539
    • View Profile
    • jinxtergames
Re: help turning script into playmaker fsm
« Reply #1 on: February 03, 2018, 11:15:50 AM »
Hi.
Here you go :



But i do think you can do this easier by creating a Physics Material place it in the collider on the ball and set it up like this:



You just need to set the initial speed faster or do this when colliding.

cel

  • Junior Playmaker
  • **
  • Posts: 96
    • View Profile
Re: help turning script into playmaker fsm
« Reply #2 on: February 05, 2018, 01:35:37 AM »
Thank you so much djaydino,

this is brilliant,
Thank you for your help!!