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 samz · Apr 08, 2012 at 03:08 PM · camera-movementstandardassetsmobile

SmoothFollow2D - Standard Assets(mobile)

im trying to modify the sideScrollSetup scene in the Standard Assets(mobile) package, the SmoothFollow2D script.

I want the camera to stop following the player when a certain point is reached and vice versa. The if statement i added works with one little problem. The camera stops fine, and when u move back from that certain point the camera follows the player again however its not a smooth transition. It sort of bounces once.

thanks

 var target : Transform;
 var smoothTime = 0.3;
 
 private var thisTransform : Transform;
 private var velocity : Vector2;
 
 function Start() {
     thisTransform = transform;
 }
 
 function Update() {
     thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y, 
     target.position.y, velocity.y, smoothTime);
       
     **if(target.position.x < 19 && target.position.x > -15) {**
         thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x, 
         target.position.x, velocity.x, smoothTime); 
     }
 }
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

2 Replies

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

Answer by samz · Apr 09, 2012 at 07:13 AM

0o0o0o thnx for your massive code lol. But i fixed it :D Well i didnt do much, just changed the smoothTime value to 0.01

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 DJSwiti · Apr 09, 2012 at 07:20 AM 0
Share

Well. With my script, your camera will follow your player only if he is in a special area. Please put your subject as resolved by saying my answer is correct.

avatar image
0

Answer by DJSwiti · Apr 08, 2012 at 06:11 PM

Hello. I can show you what I made, because i had the same problem. With this script, the camera will follow your player, but if he is X < 4 and X > 11 and Z < 1 and Z > 8

 using UnityEngine;
 using System.Collections;
 
 public class Follow2D_xy : MonoBehaviour
 {
     public Transform _Player;
     public float _cameraSpeed = 10;
     public float cam = 3;
     int iamout_x = 0;
     int iamout_z = 0;
     bool locked;
     static public float setto_x = 11;
     static public float setto_z = 8;
 
     Transform _transform;
     
     void Awake()
     {
         _transform = transform;
     }
     
     void Start(){
         locked = true;
     }
     
     void Update ()
     {
         Vector3 newPos = _transform.position;
         Vector3 pos = _transform.position;
         
         if(locked == true){
             newPos.x = _Player.position.x;
             newPos.z = _Player.position.z;
             pos.x = Mathf.SmoothStep(setto_x, newPos.x, cam * Time.deltaTime);
             pos.z = Mathf.SmoothStep(setto_z, newPos.z, cam * Time.deltaTime);
             _transform.position = pos;
             if((pos.x >= 7.8) && pos.z >= 3.8)
             locked = false;
         }
         
         if((newPos.x >= 4) && (newPos.x <= 11) && (iamout_x == 0) && (locked == false)){
             newPos.x = Mathf.SmoothStep(newPos.x, _Player.position.x, _cameraSpeed * Time.deltaTime);
             _transform.position = newPos;
         }
         else if((newPos.x <= 4) && (locked == false)){
             iamout_x = 1;
             newPos.x = 4;
             _transform.position = newPos;
             if(_Player.position.x >= 4)
                 iamout_x = 0;
         }
         else if((newPos.x >= 11) && (locked == false)){
             iamout_x = 1;
             newPos.x = 11;
             _transform.position = newPos;
             if(_Player.position.x <= 11)
                 iamout_x = 0;
         }
         if((newPos.z >= 0) && (newPos.z <= 8) && (iamout_z == 0) && (locked == false)){
             newPos.z = Mathf.SmoothStep(newPos.z, _Player.position.z, _cameraSpeed * Time.deltaTime);
             _transform.position = newPos;
         }
         else if((newPos.z <= 0) && (locked == false)){
             iamout_z = 1;
             newPos.z = 0;
             _transform.position = newPos;
             if(_Player.position.z >= 0)
                 iamout_z = 0;
         }
         else if((newPos.z >= 8) && (locked == false)){
             iamout_z = 1;
             newPos.z = 8;
             _transform.position = newPos;
             if(_Player.position.z <= 8)
                 iamout_z = 0;
         }
     }
 }

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Camera Rotation when UI is up? 0 Answers

Change a float value with the horizontal axis? 1 Answer

Camera bounds 0 Answers

Trouble with logic related to my camera smoothing 0 Answers

Rotate Camera to the object 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