- Home /
Why my player doesn't stop when it collide with the roadblock?,Collision does not work, player won't stop moving when it hit an object with collider.
So I had recently added this roadblock into my project, and I want to make the player stop when it touches or in other words collider, with the roadblocks. I have added rigidbody and collider to both objects(player and the roadblock. But when I run the game, it turns out that my player will just go through the roadblock even if I locked the roadblock's position on X Y Z and rotations. I just want to make the roadblock acting like a wall which prevents player from walking/running through. I used the transform method to move my player. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMoving : MonoBehaviour
{
public float walkingspeed;
public float runningspeed;
public float crouchwalkingspeed;
public float walkingstairsspeed;
public Transform movingObject;
public Animator anime;
bool stair = false;
// Update is called once per frame
void FixedUpdate()
{
if (Input.GetKey("d"))
{
if (Input.GetKey("space"))
{
movingObject.Translate(movingObject.right * -runningspeed * Time.deltaTime);
}
if (anime.GetBool("isCrouching") == true)
{
movingObject.Translate(movingObject.right * -crouchwalkingspeed * Time.deltaTime);
}
if (stair == true)
{
movingObject.Translate(movingObject.right * -walkingstairsspeed * Time.deltaTime);
stair = false;
}
else
movingObject.Translate(movingObject.right * -walkingspeed * Time.deltaTime);
}
if (Input.GetKey("a"))
{
movingObject.Translate(movingObject.right * walkingspeed * Time.deltaTime);
}
}
public void walkingOnStairs()
{
Debug.Log("im on stairs");
stair = true;
}
}
Your help is extremely important for me.
Thank you!
Answer by jmhoubre · Jul 19, 2020 at 12:15 PM
Hello, try to check the IsKinematics box of the Rigidbody of your RoadBlock. Good luck.
Your answer
Follow this Question
Related Questions
Rigidbody cube randomly stops moving? 1 Answer
Player keeps falling halfway through terrain floor 3 Answers
Avoid one gameObject skin in another gameObject 2 Answers
how to Apply Gravity at Run time ..????????? 2 Answers
OnCollisionEnter not triggering when two rigidbody collide via Instantiate 1 Answer