I’m new to Unity, so I would be thankful if somebody helps me with my issues.
Now I’m working over a 2D “runner” and I have 2 problems:
1) Collision with obstacles while constant moving forward
(“Forward” I mean along the X axis)
So while navigating the Player using the “A/D” it stops before Cubes with “Box Collider: on”
But I made my Player run constantly by adding this script to the Character Controller
function Update () {
transform.position.x += speed;
}
And after that the Character runs directly through the obstacles without stoping
What am I doing wrong ?
2) Square form of a Character Controller ?
My Player is a simple cube, with a texture on it.
How to change the “Character Controller” to handle an sharp-edged body? Or it allows usage of a sphere, ball or pill figure only?
Picture may describe the second issue better:
In the future, please ask questions about different issues separately. I’ll be happy to answer these anyway, though.
You should use CharacterController.SimpleMove(Vector3.right*speed) instead of changing transform.position directly. The character controller takes collisions into account while direct modifications of transform.position will be carried out regardless of collisions.
First of all, make sure your player character has a Rigidbody attached. Then, you could try attaching a box collider to the player character and adding a section to your script that uses the OnCollisionEnter or OnTriggerEnter function (which should still be activated even if your character is passing through the object). In that function, you can add a line to set the player’s forward speed to zero when it detects a collision or do whatever else you want it to do when it encounters an object.