I have a couple objects, the player who is always moving forward, and the enemy who is moving towards waypoints. The problem is I use transform.Translate and no collision is being detected. I read that transform.Translate overrides collides, Is that true? If so what’s the best way to make my character collide with objects?
I’ve never had to do such things, but from what I understand, if your objects have RigidBodies, perhaps you can use the various functions on those instead:
I’m sure someone else has better, more experienced advice to give though.
are you using character controler or other components?
@ Fizixman: Are you saying that if you apply transform.Translate to an object with a character controller it collides propperly with objects, because maybe there’s something I’m overlooking in my project? I actually think I already tried rigidbodies.Velocity, but I’ll check around for other cammnds under rigidbody, thanks.
@jeffomI’m using a Character controller, and my character has a constant forward force which is Transform.translate (0,0,1 * Time.deltaTime);
transform.Translate does not check for collision so you will need to either code those checks yourself, or move away from that method and look at CharacterController.Move() or CharacterController.SimpleMove() (I recommend the first, but it does not calculate gravity so you will need to write that in yourself).
Edit: You can of course also look at Rigidbody movement, but you mentioned you were using a CC so I suggest the above ![]()
Thanks Rob, I actually removed the character controller and just used a box collider, it works, but it does seam to twitch allot when it’s colliding with the object, any advice on that?
When it collides with the object, you need to tell it to either move around the object or stop moving, because otherwise it’s going to continue trying to move forward through the object and collision is going to stop it, hence your twitch.
I gave that a try last night, I I used
function OnCollisionEnter(hit:Collision) {
if(hit.gameObject.collider){
flyspeed = 0;
}
else{
flyspeed = 20;
}
}
It makes the ship stop when it hits but since it has a rigidbody attached it sort starts floating once it hits the space station. I’m not going for a super realistic look so I don’t need physics, but I do need to detect collision (as far as I know
) How would you recommended making it stop when it hits an object?