Why can my character go through objects with collides on them?
Hello. So, i have a character in my game that I a working on. for the most part it works perfectly fine, but Until i recently change the character movement behavior to something that works, My character can walk right through an object. For example, I have the box in my setting and when i should be colliding with it, I go straight through it!. In case you need to know, my 3d model is parented to the camera so the movement script works, and the camera has a rigid body component attached to it with continuous dynamic physics. Here is the script for my character movement:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float speed = 6f;
Vector3 movement;
Rigidbody playerrigidbody;
bool IsFlying = false;
void Start () {
playerrigidbody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate () {
// movement
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
move(h, v);
float Xrot = Input.GetAxisRaw("Mouse X");
transform.Rotate(0, Xrot, 0);
Vector3 speed = new Vector3(h, 0, v);
speed = transform.rotation * speed;
if (Input.GetKey(KeyCode.Space))
{
if (IsFlying == false)
{
IsFlying = true;
GetComponent<Rigidbody>().velocity = new Vector3(0, 6, 0);
}
}
}
void move (float h, float v)
{
Vector3 Speed = new Vector3(h, 0, v);
Speed = transform.rotation * Speed / 7;
movement.Set(h, 0f, v);
playerrigidbody.MovePosition(transform.position + Speed);
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name != "prop_powerCube")
{
IsFlying = false;
}
}
}
$$anonymous$$aybe you accidentally checked "Is Trigger" in the collider settings?
Answer by Dark_Shadow_12 · Sep 01, 2016 at 12:06 AM
Never mind, I fixed my problem :) In case anyone was wondering, The problem was that my 3d model didn't have a collider on it, so it couldn't collide with anything.
Your answer
Follow this Question
Related Questions
How i prevent 2 obejcts with kinematic checked in both rigidbodies collide? 3 Answers
How to check if gameObject is interact with multiple colliders 1 Answer
player going through walls even though it has colliders and rigidbodies 0 Answers
How do I detect a collision between two objects using Bolt? 1 Answer
my colliders don't work properly 2 Answers