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 TotalityClause · May 27, 2012 at 03:27 AM · rotationrigidbodyaddforce

Rotating Camera, and Movement help.

I'm using This to make an item move,

if (Input.GetKey ("w")) { rigidbody.AddForce(Vector3.forward * 45); }

And i was 1. Wondering if there is a way to make the an item JUST move forward, instead of rotating it, which is what this causes the item to do. For example, i used a cube to test it out, and when it starts to move, instead of it "gliding" across the ground its edge stops it and it has to "flip" over.

  1. Can i make a fixed camera that doesn't go with the rotation of the item? I have attached a camera and positioned it in the proper area for it to be a "hack and slash" (as i'm just learning right now) and when it does rotate the camera rotates with it. Now, if i get the object to stop rotating it would be fine, but i would love to know how to stop this.

3.How would i get the object to rotate based on direction while the camera is fixed? Meaning when i go forward its forward, left it turns and goes left, etc. etc.

4.in the (Vector3.forward *10); what is the substitution for "forward" for other directions? It's the only one in the script reference and -forward and backward don't work...

Thanks!

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

Answer by hathol · May 27, 2012 at 03:45 AM

Ok, for the movement: I would set the velocity directly instead of applying a force. So the code would be

 if (Input.GetKey ("w")) { 
     rigidbody.velocity = Vector3.forward * speed * Time.deltaTime; 
 }

That should solve your fliping over problem. For the camera, instead of attaching it directly to your game object, you could add a script to the camera that tells it to follow the player. Could be something as simple as

 Camera.transform.position = YourPlayer.transform.position + (Vector3)SomeOffset;
 Camera.LookAt(YourPlayer.transform.position);

Vector3 has constants for forward, right and up. If you want the negative (like a "backward") you would write "-Vector3.forward" or "Vector3.forward * -1" Remember that Vector3.forward stays the same, no matter where your object is facing to. If you want the forward vector relative to the object (the objects z axis), you can use transform.forward instead. Hope that helped.

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiating bullet and moving forward with rigidbody 0 Answers

Prevent Rigidbody From Rotating 3 Answers

Airplane goes weird on collision (Rigidbody) 1 Answer

Rigidbody.addforce then rigidbody.rotation and movement along transform.forward 2 Answers

Is it advisable to apply forces and rotations on a same object? 2 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