- Home /
Problem with moving an object and Uni2D Colliders
hi there..
i tried to create a 2D RPG styled Game. Therefor, i created a flat map with Uni2D, and it´s physic colliders.
Everything works fine.. if i add a sphere with a rigidbody.. it collides with the Uni2D Walls. Now i tried to add a small movement script to the Sphere.
this is it:
using UnityEngine;
using System.Collections;
public class Character_Controller : MonoBehaviour {
//first the publics
public GameObject Player;
public GameObject SpriteHolder;
public float MoveSpeed = 2.0f;
// now the locals
int MoveDirection;
float translationH;
float translationV;
// now the functions
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float translationH = Input.GetAxis("Horizontal") * (MoveSpeed/10);
float translationV = Input.GetAxis("Vertical") * (MoveSpeed/10);
Player.transform.Translate(translationH, -0.001f, translationV);
Player.transform.eulerAngles = new Vector3(0, 0, 0);
}
}
What happens is, that the sphere tries to climp over the colliders, floats around a bit (like rolling out) and behaves more like it´s moving on ice ._.
So i searched via Google.. and found out that i need to use the Character Controller instead of a rigidbody. Read-Done.. CC added..
But now, the object is not reacting to the colliders.. like there are no invisible walls ._.
see: http://www.imagesload.net/img/Unity_Prob01.png
http://www.imagesload.net/img/Unity_Prob02.png
I need this really urgently - cause this problem blocks nearly everything in my project (each NPC, object, enemy..etc needs to be able to react with the Uni2D colliders..)
What have i made wrong?
Your answer
