- Home /
Question by
GunMetalGames · Aug 01, 2020 at 10:44 PM ·
collisionrigidbodycollidersclippingrigidbody collision
Character is not Colliding despite having a Box Collider and Rigidbody
Howdy! As the title says: my character and parts of the environment have Rigidbody components AND box colliders. They're all the default, uniform size. I've attached pictures from the inspector tool, as well as my code below.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public GameObject player;
public float speed = 0.5f; //this variable tells Unity how many units we want to move per input. In this case, we move half of 1 unit.
public float rotationSpeed = 100.0f;
private Rigidbody rb; //establishes a variable for this code, "rb" for "RigidBody"
private void Start()
{
rb = GetComponent<Rigidbody>(); //tells Unity that "rb" means we're using the RigidBody component
}
void Update()
{
// PLAYER MOVEMENT IS HERE
Vector3 move = Vector3.zero;
if (Input.GetKeyDown(KeyCode.W)) //move forward
{
move = transform.forward * speed;
}
else if (Input.GetKeyDown(KeyCode.S)) //move backward
{
move = -transform.forward * speed;
}
if (Input.GetKeyDown(KeyCode.A)) //move left
{
move = -transform.right * speed;
}
else if (Input.GetKeyDown(KeyCode.D)) //move right
{
move = transform.right * speed;
}
//rb.MovePosition(transform.position + move); (this comment is just me keeping a copy of the rb.MovePosition command, in case I need it later.)
transform.position += move; //STRAFE RIGHT
if (Input.GetKeyDown("q"))
{
transform.Rotate(0f, -90f, 0f);
}
if (Input.GetKeyDown("e"))
{
transform.Rotate(0f, 90f, 0f);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Colliding fast moving object with a slow moving object 1 Answer
Why does my player fly through my barrier? 2 Answers
collision detection problem in fast moving object 1 Answer
Collisions While Rotating Objects Without Character Controllers 1 Answer
Stop joint from jittering when target is on other side of collider 0 Answers