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 Rares15 · Dec 24, 2016 at 11:30 AM · cameraposition

Main Camera transform position or localPosition is not working

I made an crouch script, but i have a problem at camera change y position:

 public float CameraCrouched = 0.414f;
 public float CameraUnCrouched = 0.914f;

Crouched/UnCrouched part:

     void Crouched()
     {
         controller.height = 1.45f;
         controller.center = new Vector3(0, -0.5f, 0);
         Camera main = GameObject.Find("FirstPersonCharacter").GetComponent<Camera>();
         main.transform.localPosition = new Vector3(0, CameraCrouched, 0);
         Crouch = true;
     }
 
     void UnCrouched()
     {
         controller.height = standardHeight;
         controller.center = new Vector3(0, 0, 0);
         Camera main = GameObject.Find("FirstPersonCharacter").GetComponent<Camera>();
         main.transform.localPosition = new Vector3(0, CameraUnCrouched, 0);
         Crouch = false;
     }


Comment
Add comment · Show 3
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 itsharshdeep · Dec 24, 2016 at 01:42 PM 0
Share

what is the issue ?

avatar image Rares15 itsharshdeep · Dec 24, 2016 at 02:25 PM 0
Share

I need to move the FirstPersonCharacter camera at: 0.414f, the original position si: 0.914f, I tried this what you see in code, but nothing.

avatar image itsharshdeep Rares15 · Dec 24, 2016 at 07:00 PM 0
Share

hmm.. You must need to check that this method is calling well and camera's position is assigning or not by placing the Debug.Log() or by breakpoints. if logs are printing in the console there might be possibilities that any Update()/FixesUpdate()/LateUpdate() is re-setting camera's position back again in any script like CameraCaontroller.cs

2 Replies

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

Answer by Rares15 · Dec 24, 2016 at 06:49 PM

I Solved :D

I made a new Object, i put camera in that object and i put that line at the object:

cameraGroup.transform.localPosition = new Vector3( 0, CameraUnCrouched, 0);

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 Nick15104 · Jun 16, 2018 at 04:52 AM

Yes for first person crouching as Rares15 has figured out. You can create from the first person character and add an empty game object. Then put the character camera into the empty game object and apply this script to the empty game object. I have made the numbers a public float so you can play around with the standing height and the crouched height.

 using UnityEngine;
 
 public class Crouch : MonoBehaviour
 {
     public float playerCrouched = -0.75f;
     public float playerUncrouched = 0f;
 
     private void Update()
     {
         if (Input.GetKeyDown(KeyCode.LeftControl))
         {
             transform.localPosition = new Vector3(0, playerCrouched, 0);
         }
         if(Input.GetKeyUp(KeyCode.LeftControl))
         {
             transform.localPosition = new Vector3(0, playerUncrouched, 0);
         }
 
     }
 }

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

109 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

Related Questions

UI Elements repositioning and resizing when playing game 1 Answer

Camera out of position on building/cloning to other machine,Camera out of place on another machine 0 Answers

How get position from a game object? 5 Answers

Camera isn't move position? Why my camera isn't change position? 0 Answers

Change the offset whenever the position changes 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