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 darkknightsaver1 · Jan 20, 2014 at 12:31 PM · convertcorrection

Camera speed

here is the cs file. how to make it follow player faster? and can you convert it to java file?

using UnityEngine;

using System.Collections;

public class CameraFollow : MonoBehaviour

{ public float xMargin = 1f;
public float yMargin = 1f;
public float xSmooth = 1f;
public float ySmooth = 1f;
public Vector2 maxXAndY;
public Vector2 minXAndY;
private Transform player;
void Awake () { player = GameObject.FindGameObjectWithTag("Player").transform; }

 bool CheckXMargin()
 {
     return Mathf.Abs(transform.position.x - player.position.x) > xMargin;
 }
 bool CheckYMargin()
 {
     return Mathf.Abs(transform.position.y - player.position.y) > yMargin;
 }
 void FixedUpdate ()
 {
     TrackPlayer();
 }
 
 
 void TrackPlayer ()
 {
     float targetX = transform.position.x;
     float targetY = transform.position.y;
     if(CheckXMargin())
         targetX = Mathf.Lerp(transform.position.x, player.position.x, xSmooth * Time.deltaTime);
     if(CheckYMargin())
         targetY = Mathf.Lerp(transform.position.y, player.position.y, ySmooth * Time.deltaTime);
     targetX = Mathf.Clamp(targetX, minXAndY.x, maxXAndY.x);
     targetY = Mathf.Clamp(targetY, minXAndY.y, maxXAndY.y);
     transform.position = new Vector3(targetX, targetY, transform.position.z);
 }

}

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 Wiki

Answer by GEWLAR · Jan 20, 2014 at 01:55 PM

You could multiply the move factor in those lines:

 targetX = Mathf.Lerp(transform.position.x, player.position.x, xSmooth * Time.deltaTime);
 targetY = Mathf.Lerp(transform.position.y, player.position.y, ySmooth * Time.deltaTime);

Add another variable to your Script

 var Speed = 2.0f;

And then use it to make your camera faster:

 targetX = Mathf.Lerp(transform.position.x, player.position.x, xSmooth * Time.deltaTime* Speed);
 targetY = Mathf.Lerp(transform.position.y, player.position.y, ySmooth * Time.deltaTime * Speed);
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 Michael Sanelli · Jan 20, 2014 at 02:57 PM

You can simply work on xSmooth and ySmooth variable

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

19 People are following this question.

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

Related Questions

2d camera scrolling 0 Answers

basic 2D camera setup 2 Answers

Help with conversion from javascript to c# 3 Answers

Add a polygon collider 2D using vertices of edge collider 1 Answer

How to convert a string to a type WWW 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