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 Shakti_Singh1 · Jun 19, 2021 at 01:30 AM · positioninglocalposition

Cannot move a Gameobject to desired location

Hey guys , I want to move my player to an empty GameObject (stealthKillPoint) so that I can then kill a guard. The stealthKillPoint is a child of the Guard gameobject and the below script is attached to the stealthKillPoint gameobject.

      void MoveThePlayer()  
     {
     player.transform.position=new Vector3(stealthKillPoint.position.x,player.transform.position.y,stealthKillPoint.position.z);
     player.transform.LookAt(transform.parent.transform.position);   //this is to look at the guard
     KillingAnimation();
 }

I think that the player should move to the stealthKillPoint but it stays in the same position when MoveThePlayer function is called. I printed the value of player's position which is the same as that of stealthKillPoint (-18.2,0.5,17.4) but the inspector shows that player's position is (-16,0.5,18.2). When I change the player's position manually in the inspector the player moves to the position where I want it to but I cannot make the script do the same. Player is not a child of any other gameobject and I tried using localPosition but the player again stays in the same position just its rotation is changed(I don't know why its rotation is getting affected by localPosition).I would be glad if any one could help me.

Thanks in advance.

(P.S. Nothing is static in the script)

Comment
Add comment · Show 2
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 logicandchaos · Jun 19, 2021 at 08:00 PM 0
Share

can you show how game objects are set up in inspector?

avatar image Shakti_Singh1 logicandchaos · Jun 20, 2021 at 07:38 AM 0
Share

alt text

StealthKill Distance is the child of Guard whom I am trying to kill. The player is not a child of any other GameObject. I tried to change the position of the player in the above script to(0,0,0) but it still stays at the same position. In the console it still prints its position as (0,0,0) but the inspector says otherwise. I am really confused here.

capture.png (36.6 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DenisIsDenis · Jun 20, 2021 at 09:41 AM

If the player object has a Character Controller, then it should be disabled before moving it in the script:

 void MoveThePlayer()  
 {
     GetComponent<CharacterController>().enabled = false;

     player.transform.position =
     new Vector3(stealthKillPoint.position.x,player.transform.position.y, stealthKillPoint.position.z);
     player.transform.LookAt(transform.parent.transform.position);   //this is to look at the guard

     GetComponent<CharacterController>().enabled = true;

     KillingAnimation();
 }
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 Shakti_Singh1 · Jun 20, 2021 at 12:53 PM

Thanks @DenisIsDenis , it finally worked.

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

120 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Clamping local movement 0 Answers

Script won't set right rotation? 1 Answer

Correctly positioning the start of projectile position 1 Answer

How can I get an accurate gameObject count within a frame? 1 Answer

Radial distance between two points 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