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
1
Question by Sajjoo · Jun 24, 2011 at 12:24 PM · unityiphone

Camera follow an object on just z-axis.

Hello, i am working on a bike came and i want to move my camera which just follow my bike. i am using smooth follow script but when i change my lane, my camera also change its position to x axis. which i do not want. i have tried to make changes in SmoothFollow script but could get to the right direction.

can anybody give me some hint to to achieve that as i am new in unity.

thanks

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 MrProcessor · Mar 27, 2019 at 09:30 PM 0
Share

public class CaneraFollow : $$anonymous$$onoBehaviour {

 public Transform player;

 [Range(0.01f, 1.0f)]
 public float SmoothFactor = 0.5f;

 public Vector3 offset;
 // Use this for initialization
 void Start () {
     offset = transform.position - player.position;
 }
 
 // Update is called once per frame
 void LateUpdate () {


     Vector3 desiredPosition = player.position + offset;

     desiredPosition.x = 0f;
    desiredPosition.y =0f;
     transform.position = Vector3.Slerp(transform.position,desiredPosition,SmoothFactor);
     

     
 }

} With this code, your camera will only follow your player on the z-axis.

5 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Marnix · Jun 24, 2011 at 12:28 PM

Instead of following your bike, your camera needs to follow some stub. The stub doesn't change lanes. So you need to let the stub update the positions of the bike in only 2 directions and let the third out. This way, you don't need to change the smoothFollow script.

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 Sajjoo · Jun 24, 2011 at 01:14 PM 0
Share

Thanks $$anonymous$$arnix i have done it with empty game object.

avatar image
0

Answer by Anxo · Jun 24, 2011 at 12:38 PM

 var target : Transform;
 var distance : float = 10.0;
 
 function Update(){
 transform.position.z = target.position.z - distance;
 
 }
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
avatar image
0

Answer by sanghai · Sep 07, 2011 at 02:31 PM

Hey Sajjo I have the same problem and I did not understood what Marnix is trying to say May i get the help for the same ?

I am trying to make game like Air Strike 3D where camera moves along in z axis but if plane goes in left then screen or say camera also scrolls along x axis for about 5 meter....same shd happen for right

Please help me regarding the camera view....

Thanks in advance

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 taddmencer · Sep 07, 2011 at 03:39 PM 0
Share

Ok, create an empty game object.

Place your camera and your player within said game object.

Rotate your camera to the view you want.

Attach the asset "SmoothFollow2D.js" to your camera and assign the player as the target.

This should work.

avatar image
0

Answer by sanghai · Sep 08, 2011 at 05:39 AM

Thanks taddmencer for your instant reply but this is not what I want just check out Air Strike 3D game where camera is not working as smooth flow to player but something else I am not able to figure that out.

I will give you link of youtube please check this and if u will be able to help me i will be very helpful

this is the link http://www.youtube.com/watch?v=zHkARvzsrMU

check the video after 4.42 minutes to avoid the information screen and all..

See in that screen scrolls little bit left ...right and i dont think its smooth follow if it is then please provide me the solution....if possible i will be very thankful...

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
avatar image
0

Answer by BudBroesky · Jun 24, 2014 at 04:46 AM

Use this on you main camera, i am very new to c# but I think I made a stream-lined, efficient script to follow any player on ONLY the z-axis.

using UnityEngine; using System.Collections;

public class CameraBehaviors : MonoBehaviour {

public Transform[] player;

private float playerZ;

 private Vector3 follow;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
     playerZ = player[0].position.z - 2;
     follow = new Vector3(0f,8.23f,playerZ);
     transform.position = follow;
 }

}

The part where I describe the Y axis for "follow" it just how high you want the camera, that can be changed to your liking. also the -2 in "playerZ" it just so the camera is slightly behind the player.

Hope this script 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

8 People are following this question.

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

Related Questions

Can Unity 3 build for the iOS Simulator? 2 Answers

Rendering issue on iPhone 1 Answer

Help Basketball Shooting Game 0 Answers

Camera Follow - SmoothDamp Inconsistency 0 Answers

Porting Unity Web Player game to iPhone using Unity 1.7 iPhone 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