- Home /
My character is controlled with Rigidbody, How do I make my character NOT run through objects?
I am controlling my character with a basic Rigidbody component, a capsule Collider, a simple bot control script and an Anim Triggers script. My camera is at a 3rd person view. When I run into an object. My character just runs right through it. And when I add a Rigidbody component to the object itself. Then my character pushes the object. How do I get the object to NOT move and my character to NOT go through it?
The issue is probably your bot control script. $$anonymous$$ind if I look at it? You're more than likely using something such as transform.translate(); ins$$anonymous$$d of rigidbody.velocity or rigidbody.AddForce();
using UnityEngine;
using System.Collections;
// Require these components when using this script
[RequireComponent(typeof (Animator))]
[RequireComponent(typeof (CapsuleCollider))]
[RequireComponent(typeof (Rigidbody))]
public class BotControlScript : $$anonymous$$onoBehaviour
{
[System.NonSerialized]
public float lookWeight; // the amount to transition when using head look
[System.NonSerialized]
public Transform enemy; // a transform to Lerp the camera to during head look
public float animSpeed = 1.5f; // a public setting for overall animator animation speed
public float lookSmoother = 3f; // a smoothing setting for camera motion
public bool useCurves; // a setting for $$anonymous$$ching purposes to show use of curves
private Animator anim; // a reference to the animator on the character
private AnimatorStateInfo currentBaseState; // a reference to the current state of the animator, used for base layer
private AnimatorStateInfo layer2CurrentState; // a reference to the current state of the animator, used for layer 2
private CapsuleCollider col; // a reference to the capsule collider of the character
static int idleState = Animator.StringToHash("Base Layer.Idle");
static int locoState = Animator.StringToHash("Base Layer.Locomotion"); // these integers are references to our animator's states
static int jumpState = Animator.StringToHash("Base Layer.Jump"); // and are used to check state for various actions to occur
static int jumpDownState = Animator.StringToHash("Base Layer.JumpDown"); // within our FixedUpdate() function below
static int fallState = Animator.StringToHash("Base Layer.Fall");
static int rollState = Animator.StringToHash("Base Layer.Roll");
static int waveState = Animator.StringToHash("Layer2.Wave");
Answer by JacobHockey13 · Apr 29, 2014 at 01:01 AM
I would try making the mass of your object very large in comparison to the character. Hope this helps.
Answer by Jeff-Kesselman · Apr 29, 2014 at 01:30 AM
There can be a few things wrong here:
You might have your character set to isKinematic. if you do this, then the object will not be effected by forces and this includes the force that keeps you from running through objects
You might not have a collider on the object you a re running through. Both objects need a collider for a collision to take place.
You might be moving so quickly that you are experiencing a frame miss. This is when ou or on one side of the colliding object in one frame and the other side in the next frame. The default collision only checks at frame position so you would miss the colliion. The solution is to set your moving object's Rigid Body Collision Detction mode to Continuos or Continuos Dynamic. More information on that is here: https://docs.unity3d.com/Documentation/ScriptReference/CollisionDetectionMode.html
Note that Continuos collision will chew into your frame rate, Continuoss Dynamic will do so even worse.
$$anonymous$$y character is set to is$$anonymous$$inematic, Both objects have a collider. And changing the Continuos collision setting did no good.
Thats your problem. If you are set to Is$$anonymous$$inematic then you will not get stopped by collisions. Being "stopped" is really having a force applied to you in the opposite direction of motion, and Is$$anonymous$$inematic prevents any forces from effecting the object so set.
Your answer
![](https://koobas.hobune.stream/wayback/20220613143820im_/https://answers.unity.com/themes/thub/images/avi.jpg)