# collider problem?

Hi, so I’m trying to follow the collider tutorial on unity 2d, after I tried it it worked, but there was a problem like in the video, can anyone explain? this is the code

``````using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControler : MonoBehaviour
{
public float moveSpeed;
private bool isMoving;
private Vector2 input;
private Animator animator;

private void Awake()
{
animator = GetComponentInChildren<Animator>();
}

private void Update()
{
if (!isMoving)
{
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Vertical");

Debug.Log("this is input.x" + input.x);
Debug.Log("this is input.y" + input.y);

if (input.x != 0) input.y = 0;

if (input != Vector2.zero)
{
animator.SetFloat("moveX", input.x);
animator.SetFloat("moveY", input.y);

var targetPos = transform.position;
targetPos.x += input.x;
targetPos.y += input.y;

if (IsWalkable(targetPos))
StartCoroutine(Move(targetPos));
}
}

animator.SetBool("isMoving", isMoving);
}

IEnumerator Move(Vector3 targetPos)
{
isMoving = true;
while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
{
transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
yield return null;
}
transform.position = targetPos;

isMoving = false;
}

private bool IsWalkable(Vector3 targetPos)
{
if(Physics2D.OverlapCircle(targetPos, 0.2f, level2) != null)
{
return false;
}
return true;
}
}
``````

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

• what you want
• what you tried
• what you expected to happen
• what actually happened, log output, variable values, and especially any errors you see
• links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

I agree with Kurt that it would be helpful in the future if you describe what the problem is rather than just showing the video. I noticed some jerky camera movement and the player moving through the wall at some point. I don’t know if these are the problems you are referring to or if it is something else entirely.

I’ll assume that the problem is the player clipping through the wall.

If you move a character by changing its transform.position, you are effectively just teleporting the character to the new position. Unity does not check any collision between the start and end point.

If your character has a Rigidbody2D, then you can look into using Rigidbody2D.MovePosition to move the character. This sort of movement will cause collision to be honored.

1 Like