2D plaformer, Can bug me into wall
Hey. I have a problem where i have a 2D platformer, but when i try jump down and go into the side og my blocks/walls it got stuck in the air and aslong as i hold the key that points into the wall it wont fall just stay there.
Here's my movement Code
using UnityEngine;
using System.Collections;
public class MovementController : MonoBehaviour
{
public float maxSpeed = 10.0f;
bool facingRight = true;
Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void FixedUpdate ()
{
float move = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs (move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
if(move > 0 && !facingRight)
{
FlipFacing();
}
else if(move < 0 && facingRight)
{
FlipFacing();
}
}
void FlipFacing()
{
facingRight = !facingRight;
Vector3 charScale = transform.localScale;
charScale.x *= -1;
transform.localScale = charScale;
}
}
Can Anybody help here?
Thanks In advance;
Answer by hexagonius · Oct 08, 2015 at 09:28 PM
try adding a PhysicsMaterial2D with no friction to the players collider
Answer by UnknownPluser · Oct 09, 2015 at 06:05 AM
Thanks for the answer @hexagonius. I now have the problem it keeps stop when i run normally over my surface is that because i have a collision box on each of my objects? I've aligned them perfectly an so on but it still sometimes bug a bit and won let me go anymore, before i go to the other side and then change side again.
If your floor consists of box colliders you have two options. rounded bottom for the player, or use edgecolliders for all your floor. box2d (the physics engine) is not capable of seeing properly aligned boxes as one straight collider