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 /
avatar image
0
Question by akrajanko1 · Sep 20, 2015 at 07:25 PM · 3rd person controllercamera rotation3rd person cameraobject movement

Object Movement in Camera facing direction

Hi,

I'm new to Unity and right now trying to learn the basics. I have successfully created a sphere, sphere movements, a 3rd person camera, camera rotation around the sphere. The only thing is that I want the sphere to move in the direction that the camera is facing by changing the axes values according to the camera.

And I have tried many methods, so any help would be nice. Thank you.

Player Controller Code:

public class Playercontroller1 : MonoBehaviour {

 public GameObject emptyobject;
 public float speed=0;
 private Vector3 offset;
 private Rigidbody rb;

 void Start()
 {
     rb = GetComponent<Rigidbody>();
     //count = 0;
     //setcountText ();
     //win.text = "";
 }
 void Update()
 {
     float moveHorizontal = Input.GetAxis ("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");
     Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
     rb.AddForce (movement*speed);
 }

}

using UnityEngine; using System.Collections;

Camera Controller Code:

public class cameracontroller1 : MonoBehaviour {

 public GameObject player;
 private Vector3 offset;
 private float x_rotation = 0.0f;
 private float y_rotation = 0.0f;
 
 public float x_sensitivty = 5.0f;
 public float y_sensitivty = 5.0f;
 public float speed=5;
 public Transform target;
 public Rigidbody rb;
 
 void Start () 
 {
     offset = transform.position - player.transform.position;
     rb = GetComponent<Rigidbody>();
 }
 
 // Update is called once per frame
 void Update () {
     transform.position = player.transform.position + offset;//Camera position behind ball
     x_rotation += Input.GetAxis ("Mouse X") * x_sensitivty;//Mouse input X axis
     y_rotation -= Input.GetAxis ("Mouse Y") * y_sensitivty;//Mouse input Y axis

     transform.LookAt(target);//Look at the ball
     transform.RotateAround (target.transform.position, Vector3.up, x_rotation*speed);//Rotate the camera around the ball in x axis
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

How to stop 3rd person camera going throught walls ? 1 Answer

3rd Person Camera,How would I make it so that the character will turn the way of the camera? 0 Answers

transform.rotation and localRotation automatically reset after rotating. 1 Answer

Guiding a sphere 2 Answers

How to move player in direction where the camera is aiming ? 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