- Home /
Character Controller
Hi, can you turn off ray cast detection on a character controller ?
The problem is I have a enemy as in the pictures below with a character controller for controlling his movements when looking for the player and a box collider for ray cast detection from the players weapons, the reason I'm using a box collider is so when the enemy is in different positions I resize the box collider to suite his position.
The problem is if I resize the character controller just under the box collider size he gets stuck on little obstacles like roadside curbs, so I have to resize the character controller just bigger than the box collider so he will walk/run over obstacles, this then causes problems detecting the box collider, thats why I wanted to turn off detection of the character controller so the ray cast will pass through to the box collider.
Can you tell a little more? Do you mean you want to cast a ray from the guy but it hits the collider? Then use a layer mask.
Else, let us know.
Other way is to add an empty game object outside the collider attached to the player and use it to cast the ray.
Answer by difd 9999 · Dec 02, 2012 at 02:33 PM
You could make a script so that when your enemy is still it will resize and likewise srink when moving ps. Accept answers if you want more answers
Hi, I don't want to turn it off, only ray cast detection hitting it.
Answer by fafase · Dec 02, 2012 at 06:12 PM
Is you issue to lower the CC when crawling?
Fact is you cannot rotate the CC but you can alter its height using UnityEngine; using System.Collections;
public class CCScript : MonoBehaviour {
CharacterController cc;
void Start () {
cc =GetComponent<CharacterController>();
}
void Update () {
if(Input.GetKeyDown(KeyCode.Z)){
cc.height = 0.5f;
var rotation = Quaternion.identity;
rotation *= Quaternion.Euler(90, 0, 0); // this add a 90 degrees Y rotation
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 1);
}
if(Input.GetKeyDown(KeyCode.E)){
cc.height = 2f;
var rot = Quaternion.identity;
rot *= Quaternion.Euler(0, 0, 0);
transform.position = new Vector3(transform.position.x,transform.position.y+1,transform.position.z);
transform.rotation = Quaternion.Slerp(transform.rotation, rot, 1);
}
}
}
This is a very bad little script that when you press Z, the capsule goes lying down and the collider goes small enough. Pressing E, the collider gets back to normal and so does the capsule. In my example since I am not using any kind of animation, everything happens at once and I need to set the position up a little so that the CC does not go down through the ground.
I reduce the collider as you cannot rotate it.
It might not be what you need but maybe it will lead you somewhere.
Thanks for the input, the way I've gone is to remove the box collider and resize the character controller when in the attack positions.
Your answer
Follow this Question
Related Questions
How to be tangent with the ground without a character controller? 2 Answers
How to get my character to collide with objects 1 Answer
character controller height transition 0 Answers
Does anyone know how to stop the character from rolling around? 1 Answer
Character Controller doesn't always follow it's parent position? 0 Answers