Question by
miracleforcemanga · Sep 16, 2021 at 01:50 PM ·
physics3dpuzzle
Why is collision Detection only registering in the corners?
Hi! I am developing a Top-down puzzle game, and I am currently implementing the block-pushing mechanic, and I am having a problem with the collision. it's only detecting it on the corners of the box whether I do it in the player script or have it in its own script.
I am new to unity, but not new to gamedev, so any code samples you could give would be nice.
here are both the scripts if you need them
CharacterController3D.cs
using UnityEngine;
using System.Collections;
public class CharacterController3D : MonoBehaviour {
//Variables
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
public float pushPower = 2.0f;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
// is the controller on the ground?
if (controller.isGrounded) {
//Feed moveDirection with input.
moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0,
Input.GetAxisRaw("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
//Multiply it by speed.
moveDirection *= speed;
}
//Applying gravity to the controller
moveDirection.y -= gravity * Time.deltaTime;
//Making the character move
controller.Move(moveDirection * Time.deltaTime);
//Debug info
//Debug.Log(speed);
}
}
PushableBlock.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PushableBlock : MonoBehaviour
{
void OnCollisionEnter(Collision collision){
if(collision.gameObject.CompareTag("Player")){
Debug.Log("You have collided with the movable box!");
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613043104im_/https://answers.unity.com/themes/thub/images/avi.jpg)