- Home /
OnCollisionEnter2D not triggered
when I use a OnCollisionEnter2D it isn't triggered, here is my code
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { public float moveSpeed = 5f; public Rigidbody2D rb; public Animator animator; Vector2 movement; // The Problem private void OnCollisionEnter2D(Collision2D collision) { print("It Worked"); } // Not the problem just my character controller void Update() { movement.x = Input.GetAxisRaw("Horizontal"); movement.y = Input.GetAxisRaw("Vertical"); animator.SetFloat("Horizontal", movement.x); animator.SetFloat("Vertical", movement.y); animator.SetFloat("Speed", movement.sqrMagnitude); } void FixedUpdate() { rb.MovePosition(rb.position + movement.normalized * moveSpeed * Time.fixedDeltaTime); } }
and here are some screenshots of the two objects that are supposed to collide
Edit : the code sample doesn't get formatted for some reason
Answer by vivaanbradoo1 · Sep 26, 2020 at 06:10 AM
an OnCollisionEnter2D isnt triggered you can try using OnTriggerEnter2D . for this you will need to make the collider on which your script is sitting on to "isTriggered"
Answer by BeyondTheHorizons · Sep 26, 2020 at 06:18 AM
In order to use Ontrigger, make sure to turn on the trigger button on at least one obejct
Answer by GamerDev86 · Sep 26, 2020 at 04:55 PM
What I meant was that it wasn't getting called when something collided
Your answer
Follow this Question
Related Questions
Model stuck on collider 1 Answer
2D get touch position relative to object 2 Answers
Unity 2d - moving objects with the mouse 0 Answers
simple jump-script (2D) 1 Answer
How to add collision to 2d animation 1 Answer