- Home /
Colliders Not Working
Hello,
I am making a game in which you mantain a space station. I was altering the FPSWalker script so that if you start moving in one direction, you don't stop, like in real space. Before, I could collide with the space station, because it had colliders generated (that one high res space station from the nasa package). But, when I tweaked the script, I would just pass right through it. I was using Time.deltaTime for the sliding around, so has that got anything to do with it, and if so or not, how can I fix it? Thanks.
P.S. It did this with the character controller applied and being used, so I replaced it with a collider and made the script stop referencing the CC, but with the exact same results. Also, regenerating the colliders didn't work either. I even tried using a rigidbody, but with no dice.
Code:
var speed = 6.0;
var jumpSpeed = 6.0;
var gravity = 20.0;
var random : boolean;
var slideForward : boolean;
var slideBackward : boolean;
var slideLeft : boolean;
var slideRight : boolean;
var slideUp : boolean;
var slideDown : boolean;
var inSpace : boolean;
slideForward = false;
slideBackward = false;
slideLeft = false;
slideRight = false;
slideUp = false;
slideDown = false;
inSpace = true;
private var moveDirection = Vector3.one;
private var grounded : boolean = false;
function FixedUpdate() {
if (random == false) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetKey (KeyCode.Q)) {
moveDirection.y = jumpSpeed;
slideUp = true;
slideDown = false;
slideForward = false;
slideBackward = false;
slideLeft = false;
slideRight = false;
}
if (Input.GetKey (KeyCode.E) ) {
moveDirection.y = -jumpSpeed;
slideUp = false;
slideDown = true;
slideForward = false;
slideBackward = false;
slideLeft = false;
slideRight = false;
}
// sliding
if (slideForward)
transform.Translate(0, 0, Time.deltaTime * speed);
if (slideBackward)
transform.Translate(0, 0, -Time.deltaTime * speed);
if (slideLeft)
transform.Translate(Time.deltaTime * speed, 0, 0);
if (slideRight)
transform.Translate(-Time.deltaTime * speed, 0, 0);
if (slideUp)
transform.Translate(0, Time.deltaTime * jumpSpeed, 0);
if (slideDown)
transform.Translate(0, -Time.deltaTime * jumpSpeed, 0);
}
// slide boolean activators
if (Input.GetKey (KeyCode.W) && inSpace == true) {
slideForward = true;
slideBackward = false;
slideLeft = false;
slideRight = false;
}
if (Input.GetKey (KeyCode.S) && inSpace == true) {
slideBackward = true;
slideForward = false;
slideLeft = false;
slideRight = false;
}
if (Input.GetKey (KeyCode.D) && inSpace == true) {
slideLeft = true;
slideRight = false;
slideForward = false;
slideBackward = false;
}
if (Input.GetKey (KeyCode.A) && inSpace == true) {
slideRight = true;
slideLeft = false;
slideForward = false;
slideBackward = false;
}
moveDirection.y -= gravity * Time.deltaTime;
}
All objects that move that you also wish to collide must either have a character controller or a rigid body and a collider. $$anonymous$$ake sure all colluders are NOT set to "isTrigger" as well.
If you are moving VERY fast then the default collision detection can experience a "frame miss". This is where the object is on one side of the object in its way in one frame, and the other side in the next such that they never overlap.
You can turn on continuos collision to fix this, but recognize that it greatly increases the cost of collision detection...
Like I said, I tried a character controller and a rigidbody. Setting the rigidbody to continuos dynamic didn't help either, and none of the colliders are triggers. Is it a glitch, possibly? Or am I just really stupid?
Answer by thevraptor · May 19, 2014 at 01:26 AM
Problem solved, forget about it. I used a rigidbody and a capsule collider instead of a mesh collider.
Your answer
Follow this Question
Related Questions
Multiple Colliders 1 Answer
How to attach two colliders (i.e two or more game objects )? 1 Answer
Colliding without gravity 2 Answers