- Home /
how to make a solid object?
my player is equipped with: mesh filter, mesh renderer, box collider(trigger is NOT checked), and a character controller. floors and walls are equipped with: mesh filter, mesh renderer, and a box collider(trigger is NOT checked)
so could someone tell me why my player goes through walls, please?
movement script:
var playerSpeed : int;
static var playerScore: int;
function Update () {
// amount to move player
amtToMove = (playerSpeed*Input.GetAxis("Horizontal")) *Time.deltaTime;
//move/translate the player
transform.Translate(Vector3.right*amtToMove);
}
You've probably set your movement using direct transform manipulation or you've made the character move too fast for the collision detection. Are you using $$anonymous$$ove or Simple$$anonymous$$ove? http://unity3d.com/support/documentation/ScriptReference/CharacterController.Simple$$anonymous$$ove.html
Answer by · Aug 20, 2010 at 01:58 PM
As SpinalJack suggested, direct transform manipulation prevents collision detection.
As per your comment, I think you want 3d movement (left/right, forward/back), so try using the example script provided on the CharacterController.Move function reference page.
Make sure you have a CharacterController on the player object or it won't work.
but the simple move function rotates around the y axis and moves along the x AXIS since it's in 2D, i want it to move horizontally, ins$$anonymous$$d of vertical i type horizontal, but it STILL DOESN'T WOR$$anonymous$$!!! please comment back thanks.
Your question didn't make it very clear what you wanted, but from your comment I think the example script given on the $$anonymous$$ove function would be better. It allows forward/back, left/right movement, and jump is on spacebar.
Answer by Edy · Aug 21, 2010 at 05:32 PM
Try moving your character by applying velocity-change forces:
//move/translate the player
rigidbody.AddForce(Vector3.right*amtToMove, ForceMode.VelocityChange);
Note that each AddForce adds the amount of velocity to current velocity, so you should use AddForce on each user's interaction, not on each frame. Also, in order to stop the movement you should compensate the current velocity:
//stop the player
rigidbody.AddForce(-rigidbody.velocity, ForceMode.VelocityChange);
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How come FPS charcter ignores any possible collider? 3 Answers
Character rolls consistently in all directions, but right. 1 Answer
Get the velocity of the first person controller, then apply it to an instantiated projectile? 2 Answers
Converting C# Controller from WASD Controls to Click-Based 1 Answer