Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 sanoj00 · Jun 28, 2013 at 06:23 PM · cameramovementgridsmoothtransition

Move along grid where facing

I've been trying to make a dungeon crawler, like Legend of Grimrock, and I can't get the movement right. I can't even get "snapping" movement right. Is there a way I can add 1 to the x or y (depends on where you're looking)? Or even better, slowly move the camera until it has added 1 to the vector. Here is my try...

 function Update () {
     if(Input.GetKeyDown(KeyCode.W)){
         transform.localPosition.z += 1;
     }
     if(Input.GetKeyDown(KeyCode.A)){
         transform.Rotate(0,-90,0);
     }
     if(Input.GetKeyDown(KeyCode.S)){
         transform.localPosition.z -=1;
     }
     if(Input.GetKeyDown(KeyCode.D)){
         transform.Rotate(0,90,0);
     }
     
 }

As you can see, I have only managed to snap angles, and snap only to one vector. Help?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Jun 28, 2013 at 06:26 PM

If you want to move one unit forward you can do:

 transform.position += transform.forward;

This will move the camera forward one unit since transform.forward is normalized (i.e. one unit long). To move backwards:

 transform.position -= transform.forward;

As for moving it over time, that is more complicated. Look at Vector3.Lerp() and Vector3.MoveTowards() for two functions that move things over time.

Comment
Add comment · Show 1 · 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 sanoj00 · Jun 28, 2013 at 07:15 PM 0
Share

Thanks! Works perfectly.

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.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Smooth Camera Movement script with problem. 0 Answers

How to make sliding room transitions like in Mega Man? 1 Answer

Edit SmoothFollow.js to change height and distance vars smoothly on some triggers 1 Answer

What is the best way to make smooth camera movement and rotation? (with my script) 1 Answer

Smooth Attached Object movement 1 Answer


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