My player rigid body wont collide
complete beginner here, having a hard time finding this.. i have tried another script and player collisions works well on my walls..
are these functions not compatible with rigidbody or collision?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TouchMovement1 : MonoBehaviour { public float moveSpeed = 3f;
public Rigidbody2D rb2d;
private void FixedUpdate()
{
TouchMove();
}
void TouchMove()
{
if (Input.GetMouseButton(0))
{
Vector3 _mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(_mousePos.x, _mousePos.y, transform.position.z);
}
}
}
Answer by Toastbyte · Jan 18, 2021 at 01:06 PM
@dansemur There could be many reasons why your object is not colliding. And it is probably unrelated to your script.
Got to the editor and make sure your rigidbody2d is enabled and attached to a collider 2d. Both colliding objects must have 2D collider components if you want them to work with 2D rigidbodies.
Make sure "is Trigger" is unchecked on both colliders.
Test out your rigidbody2d with the object you want it to collide with before you add scripts to it.
Your answer
Follow this Question
Related Questions
Collision between two 2D objects. 1 Answer
Why is new Vector3 stronger when player is in the air? 0 Answers
Figuring out what the acceleration will be before applying force to RigidBody2D 0 Answers
Strange physics on RigidBody when Collider enabled (locked axis) 2 Answers
Is there any reason to have a rigidbody on a gameobject that doesn't have a collider? 1 Answer