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 /
  • Help Room /
avatar image
0
Question by FreakyMex · Aug 11, 2017 at 06:53 AM · camera-movementtransform.positionaxisjoystick

How can I apply a position (and not a translation) to my camera related to an axis value

Hello,

I've been trying a lot of different ways to do this, reading the docs and tutorials and I still didn't managed it. I want my camera to move according to a joystick position, between UP (=1) and down (=1). But I don't want it to be translated according to the joystick value (althought that's what I get). I want the camera to move only when the joystick value changes.

When the joystick is =+1, the camera should be at a maximum position along Z axis. If the joysticks stays UP (=1), the camera should stay at this position. If the joysticks then gets 75% UP (=0,75), then the camera should go BACKWARDS to move to a position representing 75% of the distance between the initial position and the maximum position.

I don't know if you will get what my I mean.

Here is my actual code :

     public Vector3 Campositionworldinit;
     public Vector3 Campositionlocalinit;
     public Vector3 Campositionworldtarget;
     public Vector3 Campositionlocaltarget;
     public Vector3 Campositionlocaltarget2;
     public Vector3 Campositionworldactual;
 
 
     void Start()
     {
         Campositionworldinit = transform.position;
         Campositionlocalinit = transform.InverseTransformPoint(Campositionworldinit);
 
     }
 
 
     void Update()
     {
 
         Campositionworldactual = transform.position;
         Campositionlocaltarget = Campositionlocalinit;
         Campositionlocaltarget.z = Input.GetAxis("Joystick1X"); 
         Campositionlocaltarget2.z = Campositionlocaltarget.z - Campositionlocalinit.z;
         Campositionworldtarget = transform.TransformPoint(Campositionlocaltarget2);
         print("Campositionlocaltarget2.z" + Campositionlocaltarget2.z);
 
         transform.position = Campositionworldtarget;
 
     }
 }

Another weird thing ; when my joystick is on neutral position (=0), there is no printing for Campositionlocaltarget2.z is the console (which should be = 0). Only preceding values. Why ?

Thank you very much for your kind help.

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

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

112 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 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 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 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 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 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

hi all im trying to add fire stick to my shooter.. 0 Answers

Get camera position back to starting position 0 Answers

Joystick 3rd Axis problem on Linux 0 Answers

X360 Controller detection gives uneven quadrants 0 Answers

How to make an object move in the direction another object is facing on 2 axis? 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