Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by LieutenantIvan · Apr 02, 2016 at 08:03 AM · camerarotationobjectmousecamera rotate

Object Rotate with Camera

I have game where I have a rigid body cylinder on a terrain. I have the Main Camera in mouse orbit with the cylinder, (using the MouseOrbit.js with cylinder as target). I also added a script so when the 'W' key is pressed, the cylinder moves in one direction.

 #pragma strict
 var speed : float;
 var target : GameObject;
 function Start () {
 
 }
 
 function Update () {
 
 if (Input.GetKey(KeyCode.W)){
     
 
     transform.Translate(-Vector3.forward*speed*Input.GetAxis("Vertical"));
 }
 }


What do I add to make the cylinder's direction change with the camera's direction so that the forward direction is pointing away from the camera. So basically it's like a third person control.

alt text

So basically it needs to be like a third person player when 'W' is pressed, the cylinder needs to move away from the camera and the mouse changes the direction.

Thanks in advance.

help.png (54.0 kB)
Comment
Add comment · Show 5
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 Inok · Apr 02, 2016 at 12:53 PM 0
Share

Buddy, time to update your standart assets package and import Cameras package, there you find many work ready camera setups, or build camera rig based on these scripts.

avatar image LieutenantIvan Inok · Apr 03, 2016 at 12:13 AM 0
Share

How do I get it?

avatar image LieutenantIvan Inok · Apr 03, 2016 at 12:16 AM 0
Share

Also what script would I be looking for and what do I exactly do.

avatar image LieutenantIvan Inok · Apr 04, 2016 at 12:21 AM 0
Share

Sorry but you haven't replied yet. I need to know which script.

avatar image LieutenantIvan · Apr 03, 2016 at 01:40 AM 0
Share

I would also prefer it to be JavaScript not C#.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Abhiroop-Tandon · Apr 04, 2016 at 08:41 AM

Put the camera as a child of your player and it should work !

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 LieutenantIvan · Apr 04, 2016 at 09:47 PM 0
Share

Sorry but hat makes no difference.

avatar image Abhiroop-Tandon · Apr 05, 2016 at 08:36 AM 0
Share

Did you remove the script you added ??

avatar image LieutenantIvan Abhiroop-Tandon · Apr 05, 2016 at 08:57 AM 0
Share

Which script? For the controls did nothing but not allow me to move forward. The $$anonymous$$ouse Orbit script only just made the camera stay in one place.

avatar image Abhiroop-Tandon Abhiroop-Tandon · Apr 05, 2016 at 03:19 PM 0
Share

Look if you place the camera as a child of the player, the movement and rotation of the child depends on the parent (the player). So i dont get why it is not working for you, you should be doing something wrong.

avatar image
0

Answer by LieutenantIvan · Apr 05, 2016 at 08:59 AM

I have decided just to make 'A' and 'D' rotate the cylinder.

 #pragma strict
 var speed1 : float = 0.2;
 var speed2 : float = 1;
 var target : GameObject;
 function Start () {
 
 }
 
 function Update () {
     if (Input.GetKey(KeyCode.W)){
         transform.Translate(Vector3.forward*speed1);  
     
     }
     if (Input.GetKey(KeyCode.D)){
         transform.Rotate(Vector3.up*speed2);  
     }
     if (Input.GetKey(KeyCode.A)){
         transform.Rotate(-Vector3.up*speed2); 
     
     }
 }

However anymore input on how to solve this is very much welcomed.

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

74 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

Related Questions

Camera rotation with mouse cursor 0 Answers

Rotate ball in camera's direction.... 0 Answers

Make the camera rotate around the player and face the player. 1 Answer

Rotate towards mouse pointer 1 Answer

FPS camera jitters while moving and turning 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