- Home /
Character doesen't collide
Heyhey... I am currently trying to make a platformer in unity. I started writing code for the Character but it won't collide with anything, though the character and the surroundings have collider components attached. The following code is for the Character...
private var CharMovement = Vector3.zero;
public var speed = 2;
function Update () {
Movement();
//Actually move Character
transform.Translate(CharMovement * Time.deltaTime);
}
function Movement ()
{
if(Input.GetButton("Right"))
{
CharMovement.x = -1 * speed;
}
else if(Input.GetButton("Left"))
{
CharMovement.x = 1 * speed;
}
else
CharMovement.x = 0;
}
Sry I am new to unity... please help
Answer by dannyskim · Jan 02, 2012 at 08:03 PM
Does your character have a rigidbody attached to it? If it doesn't, I would suggest you add this and set it to isKinematic since you are moving the character by means of Translation and not adding physics forces to it.
A game object with a collider but without a rigidbody is considered a static collider, and typically should not be moved in a scene:
These are GameObjects that do not have a Rigidbody attached, but do have a Collider attached. These objects should remain still, or move very little. These work great for your environment geometry. They will not move if a Rigidbody collides with them.
The collision system is best used in conjunction with rigid bodies and physics. If you want you can try and switch to Triggers instead which may be a little bit more reliable if you do not plan on using rigid bodies.
http://unity3d.com/support/documentation/Components/class-BoxCollider.html
Answer by corpius4 · Jan 02, 2012 at 08:04 PM
if you are using java script, it is:
CharMovement.x -= 1 * speed;//right
CharMovement.x += 1 * speed;//left
since you didn't put"+=/-=" and put a "=", the command might have interfered with the regular physics
Answer by Braindrain85 · Jan 03, 2012 at 12:16 AM
Thank you for the fast answers. I tried both approaches and still the Charakter-Dummy slides through the ground plane. When I turn "is kinematic" off in the rigidbody, the Dummy behaves correctly and collides with the floor.... very weird... Here is a Picture of my Problem
It isnt that clear. Do you mean collision with the grass? That because unity terrain (Like whatever you make on the terrain trees grass etc) do not have colliders :). And if you do not want it to slide just increase the drag?
No, the grass has no colliders... only the plane beneath it. And I dont worry about the sliding. It is just that I want the capsule "walk" on top of that plane without intersecting...
Your answer
Follow this Question
Related Questions
Make characters go through each other 1 Answer
When walking, my character will not change sprites. 0 Answers
How to Make Characters Stick to Walls? 2D (c#) 2 Answers
Kinect issue with Character Movement while in flight 0 Answers
2D Movement [HELP!] 0 Answers