- Home /
How to restrict for a player movement? Player can go thru the wall.
I have player with next properties:
Player move code fragment:
if (isMoveLeft)
{
var angle = transform.eulerAngles.z+this.turnSpeed ;
float yAngle = Mathf.LerpAngle(transform.eulerAngles.z, angle, this.rigidbody.velocity.magnitude * Time.deltaTime );
var rotation = Quaternion.Euler( 0, transform.eulerAngles.y,yAngle );
rigidbody.MoveRotation( rotation);
}
this.rigidbody.velocity = this.transform.up * flyingSpeed* Time.deltaTime;
And I have 'wall' (With box collider and physic material)
'bounciness' 1,
'static friction' 100
I cannot go thru the wall instantly - collider is working! But if I will move in that direction for a few seconds player will go thru.
What i am doing wrong?
I want my wall to stops player and that's it.
Something like this doesnot helps:
void OnCollisionEnter(Collision collision) {
flyingSpeed=0;
}
Are you sure that behavior is firing at all and setting the speed back to 0?
@agoahbern at the beginning player will stuck and then can move forward.
Answer by findus_l · Oct 22, 2013 at 10:34 AM
I think the player has to be a trigger so OnCollisionEnter is called.
But you should not need this method. I am not sure but i think if you would make the player move using physical forces the colliders would react and he would be stopped by the wall. Without the callback beeing called or used.
no OnCollisionEnter isn't called if one is trigger as it passes right through him
OnColisionEnter is called when both are colliders
OnTriggerEnter is Called when 1 is trigger and other is collider and not both triggers
Character controller works fine for not going through things with Controller.move iirc
Your answer
![](https://koobas.hobune.stream/wayback/20220613120357im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to get Satisfying Collision Physics 1 Answer
Punching a crate 0 Answers
Imported 3D models collisions 1 Answer
FPS Tutorial: Why do my grenades go through the walls? 3 Answers