Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 WalidMohamed · Aug 13, 2016 at 05:42 PM · unity 5cameratransformpositionoffset

Help! I want to make a following camera but in with Y position is constant ?

i wanna make the camera follow my object with fixed distance between them ,but without changing the y position (Distance of y axis between object and camera ) . Knowing that the object moves right and left and jumps thanks a lot.

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 EDevJogos · Aug 13, 2016 at 06:43 PM 0
Share

Can't you set the camera as a child of your object ?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DiegoSLTS · Aug 13, 2016 at 07:09 PM

The most simple way I can think off is something like this...

 public class Follow extends MonoBehaviour {
     [SerializeField]
     Transform target;
     [SerializeField]
     Vector3 offset;
 
     void Update() {
         Vector3 newPosition = new Vector3(target.positions.x + offset.x, offset.y, target.position.z + offset.z);
         transform.position = newPosition;
     }
 }

Attach that script to the camera, drag and drop the object that should be followed as the target and set the offset to the fixed distance between the camera and the object.

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 WalidMohamed · Aug 14, 2016 at 01:44 PM 0
Share

thank u ^ ^

here is a slight change to adjust the position of the camera

using UnityEngine; using System.Collections;

public class CameraFollow : $$anonymous$$onoBehaviour {

 public Transform thePlayer;

 private Vector3 offset;

 void Start() {
     offset = transform.position - thePlayer.position; 
 }

 void Update() {
     Vector3 cameraNewPosition = new Vector3(thePlayer.position.x + offset.x, offset.y, thePlayer.position.z + offset.z);

     transform.position = cameraNewPosition; 
 }

}

avatar image
0

Answer by DevDavisC · Aug 13, 2016 at 07:30 PM

This should work fine

 public class CameraFollow : MonoBehaviour {
 
     private GameObject player;
     //public float cameraSpeed = 5.0f;
 
     // Use this for initialization
     void Start () {
         player = GameObject.FindGameObjectWithTag ("Player");
     }
     
     // Update is called once per frame
     void FixedUpdate () {
         //X position follow
         Vector3 camPos = transform.position;
         camPos.x = player.transform.position.x;
         //camPos.z = player.transform.position.z; // only use if you want to follow from the player's z coordinate
         transform.position = Vector3.Lerp (transform.position, camPos, 15 * Time.fixedDeltaTime);
     }
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 WalidMohamed · Aug 14, 2016 at 01:44 PM 0
Share

thanks ^ ^

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i move a GameObject to the same height as another GameObject? 0 Answers

Copy position from one object to another on one axis 0 Answers

moving a transform by 10 but it goes exra... 1 Answer

How to make Camera position Independent of its Rotation? 1 Answer

Cinema 4d to unity (Transform/position) 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