I’m trying to do a simple forced scrolling platform game as a learning project for myself in Unity.
So far everything is going ok. I’ve got a constant, randomly generated platform scrolling across the screen and I’ve got my character running along it, jumping from building to building fine, but for what ever reason, the player can move through the side of the buildings (basic, solid collision blocks (tried Box Collider and mesh generated)), yet doesn’t fall through them if you run along the top of them.
I’ve been searching through the forum and the common problem seems to be high speed collisions which I’m fairly sure isn’t the case here as I can land on top of the boxes fine and never fall down through them.
I’ve tried adding a “CollisionFlags.Sides” to see if it returns anything, but I don’t get anything from it, yet I do from “CollisionFlags.Below” so I’m at a lose on where to look.
I’m using a slightly modified version of the CharacterController (allowing me to move while jumping), but otherwise everything is pretty straight forward.
If anyone can point in the right direction or know of any examples that would be great as I’ve been stuck on this now for most of the day and it’s starting to get annoying.
Thanks in advance,
Mike.
You say forced scrolling…? Do you mean the character stays still laterally in the scene while the scenery moves? I don’t think the CharacterController would work as you expect if this is the case. The best way to go with this would be to move the character in a static scene, but make the camera track its lateral position exactly. The effect will still be a constant scroll, but since the player is moving, the collisions will work as expected with the CharacterController.
Thanks for replying. I’ve tried that (stopped the camera from moving and stuck one of the prefabs there to test it) but it made no difference. It’s a strange problem ans I know it’s going to be something really simple I’ve done wrong.
I’m currently off trying to play just with the character controller by itself to see if I can see where I might be going wrong and then fingers crossed I’ll be able to see my mistake.
Thanks,
Mike
Well I think I know what’s causing the problem, but I don’t know how to fix it.
The script that forces the constant movement seems to ignore any collision that might stop it from moving.
The way I’ve got it to constantly move is to attach the following to the player:
transform.Translate(Vector3 (playerspeed,0,0) *Time.deltaTime);
If I remove this and run around normally, it works fine.
Does anyone have any ideas how to prevent this?
Thanks,
Mike.
Something I forgot to mention… the CharacterController’s collision detecton only works if you use its Move or SimpleMove functions to move the character. Are you doing this or using transform.Translate?