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 olivierus · Sep 06, 2012 at 01:27 PM · c#camerapositionplayer

player goes crazy when using this, help!

he guys,

this is a little bit of code that has to make the camera go smoothly from one to another point. but it won't work.

could some one tell what i did wrong(i'm not the best at coding at all)

 using UnityEngine;
 using System.Collections;
 
 public class camerascript : MonoBehaviour {
 
     public Transform target;
     
     public float max;
     public float min;
     
     public bool setOn;
     
     public float turnSpeed;
     
     void Start () 
     {
         
         turnSpeed = 1f;
         
     }
 
     void Update () 
     {
         
         Vector3 smooth = new Vector3(transform.position.x, target.position.y, transform.position.z + Mathf.Lerp(min,max, Time.deltaTime));
         
         cameraPosition();
         transform.position = smooth;
         
     }
     
     public void cameraPosition ()
     {
         
         if(setOn == false)
         {
             
             min = max;
             max = 3f;
             
         }
         else if(setOn == true)
         {
             
             min = max;
             max = -3f;
                 
         }        
     }
 }
 

thanx a lot

olivierus

(ow bytheway the Seton == activated in other script :) )

Comment
Add comment · Show 6
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 Piflik · Sep 06, 2012 at 01:44 PM 0
Share
  1. setOn is always true or false, so the last else will never be executed.

  2. the order of your commands is extremely strange. Not sure if this is intended, but every change you make will be used in the following frame.

What does 'Player goes crazy' mean?

avatar image olivierus · Sep 06, 2012 at 02:26 PM 0
Share

@piflik : 1. oke, i fixed that part, thanks for saying. 2. yes like i said i'm not very good at program$$anonymous$$g.

it just goes straight down the ground, and the player won't show up.

avatar image ThermalFusion · Sep 06, 2012 at 08:49 PM 0
Share
   Vector3 smooth = new Vector3(transform.position.x, target.position.y, transform.position.z + $$anonymous$$athf.Lerp($$anonymous$$,max, Time.deltaTime));

This tells the object to set the X position to the same, set the Y position to the target's Y position, and then set the Z position to it's current position + a lerped between -3 and 3 based on delta time.

Your object would move continuously in the z axis, flying away in one direction maybe changing direction when you toggle Seton.

avatar image olivierus · Sep 07, 2012 at 05:21 AM 0
Share

@thermalfusion yes that is exactly what happens, but how can i make it that he goes smooth from 1 position on z to the other position on z?

avatar image Piflik · Sep 07, 2012 at 11:09 AM 0
Share

Try using target.position.z ins$$anonymous$$d of transform.position.z, that will at least get rid of the flying-away-part...but I am not sure if the script then does, what you want it to do.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

9 People are following this question.

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

Related Questions

Camera Follow Player using a path 0 Answers

C# - Offset In-Air Camera from Current Object Position 1 Answer

Input Controls Camera on a Predetermined Path. 1 Answer

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

Lock on opponent in UNET (C#) 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