• 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
Question by Hyperactive · Nov 16, 2016 at 02:44 PM · cameramovementvelocityforceconstant

Move 3D camera on 2D plane

Hi All,

I've got a tricky problem I'm trying to find an easy solution for.

I'm building a game where the player is going down a tunnel, vertically. The speed is constant, just moving down this tunnel at the same speed from start to finish. The way I've built this is the player is static in space (0,0,0) and the tunnel spawns in sections bellow him (0,-10,0) and moves to a point upwards (0,10,0) and then disappears. The tunnel infinitely spawns underneath him and moves up, to make it seem like he's moving down. Pretty standard.

Now, the problem I'm having is I want the player to be able to move to the edges of the tunnel, on the x/z axes. I've currently attached a rigidbody to my main camera, and a script with only:

 transform.Translate(Vector3.forward * Time.deltaTime);

This almost does what I need, except I don't want the camera to actually move forward (in this case, down the tunnel on the y axis), just move along the x/z plane depending on where the user looks.

So I could of course just have a collider on the player, and an invisible floor with a collider, which does work, but it's nasty. I'm trying to find something clean and sensible: Constant 2D movement along the x/z axes in the direction the camera is looking.

Thanks in advance.

Hyper

Comment

People who like this

0 Show 2
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 TreyH · Nov 16, 2016 at 03:03 PM 1
Share

A 2D plane by definition is a subset of 3D space where all values can be attained from two linearly independent 3D vectors. In the case you want just the X/Z components, you'll want to fix the Y value for your translations to to value you see fit.

For your translations, you would just replace that component manually.

avatar image Hyperactive TreyH · Nov 16, 2016 at 03:16 PM 0
Share

Resetting the Y position every frame is indeed a good solution! I like it.

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

88 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 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 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 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 to stop player velocity completely 1 Answer

How do I move this rigidbody? 1 Answer

Bug, while checking if rigidbody is moving 0 Answers

Make an object move forward on its own 2 Answers

Object jitters when the scene starts 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges