• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mabit · Jul 09, 2014 at 10:21 AM · rotateturningover time

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mabit · Jul 10, 2014 at 02:08 AM 0
Share

If you are giving an answer please can you provide some code too. I am not the strongest coder.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mabit · Jul 09, 2014 at 10:52 AM 0
Share

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.

avatar image Armand · Jul 09, 2014 at 11:05 AM 1
Share

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.

avatar image mabit · Jul 09, 2014 at 11:08 AM 0
Share

Thanks for the answers. Will have a look at coding that.

avatar image mabit · Jul 10, 2014 at 02:35 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I rotate a Transform over time? 1 Answer

Rotate Texture Over Time 1 Answer

Sidescroller Turning 1 Answer

Camera rotation around player while following. 6 Answers

Problem turning empty object containing multiple objects 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges