I am attempting to make a custom 2D CharacterController in Unity 4.3 and I am trying to make an IsGrounded function but it’s registering raycasts and linecasts on only the player. Here is my code, simple enough.
using UnityEngine;
using System.Collections;
[RequireComponent (typeof(Rigidbody2D))]
public class CharacterMovement : MonoBehaviour {
public LayerMask ground;
float PlayerHeight;
void Start () {
PlayerHeight = GetComponent<BoxCollider2D>().size.y;
}
// Use this for initialization
void Update () {
print (IsGrounded());
}
public bool IsGrounded () {
bool hit = Physics2D.Linecast(Flatten(transform.position), new Vector2(transform.position.x,transform.position.y - (PlayerHeight * -.5f)), 1 << ground.value);
return hit;
}
}
As a note, I am using 2DToolkit for my spritework and I removed any code (potentially) irrelevant to the problem.
Have you by chance figured this out? I'm facing the same problem right now. Thanks!
– nngafook