- Home /
Stay in a pipe
I am working on a game where players fly on rails through a pipe.
The solution I have at present is that when you approach a turn you hit a trigger and turn 90 degrees over time. This works as long as the turn is 90 degrees and only at one speed.
I am looking for some suggestions of a better way of doing this so I can have any shape turn at any speed.
Below is a video of the prototype
https://www.youtube.com/watch?v=ikjEM1xlXHg
Any help is most appreciated.
Kenny
If you are giving an answer please can you provide some code too. I am not the strongest coder.
Answer by Armand · Jul 09, 2014 at 10:31 AM
One way to accomplish that would be to cast a ray to either side of the bend. Make the player ship keep a constant distance from the hit point of the raycast, and rotate the ship so that its rotation is perpendicular to the surface normal of the raycast hit point on the matching axis. This way it will work inside any pipe, though you have to make sure you are casting rays on the right plane - that is, if the bend turns left or right, you have to shoot the ray left or right, not up or down.
Thanks for the reply.
I think I understand what you are saying. To take that a step further could that work by raycasting in all 4 directions (up, down, left, right) then by taking the sharpest normal from the sharpest angle as that would be the inside turn.
The reason I am saying this is that once you start turning up and around in the pipe a left turn is not always a left turn it depends on where you are in the space. It was one of the headaches when designing the Jam level.
That is indeed true, which is why you should use the local space of the ship, and translate the surface normal to that space as well. Then it won't matter how the ship is rotated in relation to the world space.
Also, you could cast rays to four directions like you said, but keep left/right and up/down separate. That way you can make bends that turn both left AND up, or right and down, and so on. Just turn the ship on the corresponding plane independent of the perpendicular plane.
I have spent a few hours working on this. I can get the normal from the hit.normal, but its very jerky.
Do you have a small code example to show how to do this?
Your answer
Follow this Question
Related Questions
How do I rotate my character smoothly? 1 Answer
Rotate object horizontal with local position and localrotation 0 Answers
Flip over an object (smooth transition) 3 Answers
How can I rotate a Transform over time? 1 Answer
Rotate Texture Over Time 1 Answer