Reputation: 39
I have a player and a platform on my scene. The scene is in 2D.
Here are platform's components:
Here are player's components:
[]
To move the player - I use SimpleMove() method:
CharacterController controller;
public float speed = 3.0F;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
float movement = Input.GetAxis("Horizontal");
Vector2 movementVector = new Vector2(movement, 0f);
controller.SimpleMove(movementVector * speed);
}
Upvotes: 1
Views: 1475
Reputation: 753
I'm afraid what you're trying to achieve will not work as expected. Character Controller is actually intended for 3D and you're expecting it to collide with 2D colliders that works differently and most importantly are not compatible
Character Controller brings 3D capsule collider to it's object - see https://docs.unity3d.com/Manual/class-CharacterController.html
You may try to experiment with adding some 2D collider and eventually also RigiBody2D to your object. Character Controller is intended also for cases without using physics (except collisions), so if that's the case also for your 2D game, creating own character controller could be quite straight forward option as well
Upvotes: 1