I’m having problems with my character’s Rigidbody. Basically I have two scripts both are which attached to the player, the first script is my player movement script which also have a Addforce bounce variable with it and the second script is a disabling script which disable my player movement script for two seconds so my bounce variable can work. As mention above my I’m having problems with the Rigidbody attach to my player. When my player collides with an object that is set to trigger, my players movement gets really weird and shaky from the direction of where the object came from, until the player collides with another box collider then it goes back to normal!!! How would I stop this from occurring? Here are all three scripts. Thank you:
Disabling script:
using UnityEngine;
using System.Collections;
public class Disablingscript : MonoBehaviour {
public Playermovement playerMovementRef;
void Start ()
{
StartCoroutine("DisableScript");
}
IEnumerator DisableScript ()
{
playerMovementRef.enabled = false;
yield return new WaitForSeconds(2f);
playerMovementRef.enabled = true;
}
}
Player movement script:
using UnityEngine;
using System.Collections;
public class Playermovement : MonoBehaviour {
public float speed = 15f;
private Vector3 target;
void Start () {
target = transform.position;
}
void Update () {
if (Input.GetMouseButtonDown (0)) {
target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
target.z = transform.position.z;
}
transform.position = Vector3.MoveTowards (transform.position, target, speed * Time.deltaTime);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Bouncy object")
GetComponent<Rigidbody2D>().AddForce(transform.right * 500);
}
}