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;
}
}
}