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 treceguete · Mar 20, 2015 at 11:28 AM · cameraplayermoving

Moving the Camera around my Player

Hey guys,

i am trying to build up a game where i am moving a sphere as my Player with the Arrow-Keys.

Everything works fine!

My Problem is that i want to build a labyrinth, in which the player sees the Playersphere from behind and a little bit up. When the Player is changing directions with the Arrow-Keys the Camera should move around the object, so that the player ist always looking into the direction he is moving. Just like in Need for Speed or other similar Games, when u turn around the camera turns around, too.

Is there a posibility to do so? A tutorial or anything that can help me would be awesome.

Greets treceguete

I am sorry for my bad english, unfortunatelly its not my mothertongue...

Comment
Add comment · Show 1
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 ShabihDesperado · Mar 20, 2015 at 12:29 PM 0
Share

There's a lot of ways to do it, but any it's simply. Just try with rotate around when the direction respect the camera is not foward. http://docs.unity3d.com/ScriptReference/Transform.TransformDirection.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Digital-Phantom · Mar 20, 2015 at 12:16 PM

Just make your camera a child of the sphere. (in the hierarchy drag your main camera onto the sphere) It then becomes a child of the sphere.

Set the cameras co-ordinates (X Y Z) to 0, 0, 0 (that's dead centre of the sphere)

Now move your camera back and up a little to a position where the view is good for you.

Now the good bit... wherever you move your sphere the camera will follow, whenever you turn/rotate your sphere the camera will turn with it.

:)

Parent/child positioning/movement tutorial

http://unity3d.com/learn/tutorials/modules/beginner/editor/the-hierarchy-and-parent-child-relationships

This is a very basic script for a simple camera follow control.

 #pragma strict
 
 var target : Transform;
 
 var distance : float;
 
 
 function Update()
 {     
     transform.position.z = target.position.z -distance;
       transform.position.y = target.position.y+25;
      transform.position.x = target.position.x;
 }


Target is the transform/object that you want the camera to follow. (in your case the sphere) Put this script onto your main camera and play around with the positioning until you get the desired result.

:)

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 ForeignGod · Mar 20, 2015 at 12:20 PM 0
Share

By doing this the camera would also rotate with the spehere's spin. As in through ground and such, i guess he don't want the camera to be in "total lock"

avatar image Digital-Phantom · Mar 20, 2015 at 12:30 PM 0
Share

well the OP didn't state if the sphere was spinning or not, he just said it was being moved. Anyway have edited my answer to add a tutorial and a basic camera follow script for the OP

;)

avatar image treceguete · Mar 20, 2015 at 01:06 PM 0
Share

Thank You. I will see what i can do. I just dont know how to integrate the PlayerSphere into the script of the camera, but i'm sure i will find a solution for that.

avatar image treceguete · Mar 20, 2015 at 05:00 PM 0
Share

Hey, i am not able to integrate your code into my Program, because i dont understand most of it, Unity does not know types like var or transform.position... I am using C#.

$$anonymous$$aybe you can help me with that:

CameraController - Your Code: using UnityEngine; using System.Collections; //using pragma.strict;

public class CameraController : $$anonymous$$onoBehaviour {

 public PlayerController  Transform;
 private float distance;

 void Start()
 {
     distance = 10;
 }
 
 
 void Update()
 {     
     //transform.position.z = PlayerController.moveHorizontal.z -distance;
     transform.position.y = y+25;
     //transform.position.x = PlayerController.moveVertical.x;
 }

}

PlayerController - $$anonymous$$y Code:

using UnityEngine; using System.Collections;

public class PlayerController : $$anonymous$$onoBehaviour {

 public Rigidbody rb;
 public float speed;
 
 void Start()     
 {
     rb = GetComponent<Rigidbody>();
 }

 void FixedUpdate()
 {
     
     float moveHorizontal = Input.GetAxis ("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");
     Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
     rb.AddForce(movement * speed * Time.deltaTime);
 }

}

I am not able to integrate the position of the Player into your Code.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Weapon not updating position and moving as Player moves 0 Answers

My player glitching on moving collider 0 Answers

Camera Problem 1 Answer

Unity 2D Position Issues 0 Answers

Player rotates with camera(face same direction as the camera) 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