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 /
avatar image
0
Question by Marks98 · Feb 05, 2018 at 09:03 PM · collidertransformbugnot workinghit

transform.position not working in OnControllerColliderHit

Hi. I have code with detection player collider with another blocks. In previous project and version of unity this me working. I using for detection this method: void OnControllerColliderHit(ControllerColliderHit collision) I have also Debug.Log for debuging, if the collider detection working. But if i insert into this method these code, nothing happaned: transform.position = new Vector3 (0, 0, 0); I am tryed another method like another coordinates, GameObject.transform.position atc. In previous project working this correctly but now it not working. For detection with another object i using these: if (collision.gameObject.name == "Dropp") Another interested thing is, when i place piece of the code with the transform.position..... in the another part of the code, it works perfect. Any case when this is not working is in my method with detection. Do i anything wrong? If i do anything wrong, why it is worked in previous version and another project?

Thanks all. Marks

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 Timo326 · Feb 05, 2018 at 10:00 PM 0
Share

Can you show us more parts of your code? Sounds like you made a mistake somewhere else in your code where you don't expect it.

avatar image Marks98 Timo326 · Feb 06, 2018 at 03:26 PM 0
Share

$$anonymous$$y code:

     void OnControllerColliderHit(ControllerColliderHit collision){
     Debug.Log("a");
     if(collision.gamobject.name = "Dropp"){
     Debug.Log("b");
     Debug.Log(transform.position);
     transform.position = new Vector3(0,0,0);
     Debug.Log(transform.position);
     }
     }

When i collision with any object, it shows me a. If i collision with object named Dropp, it show me b and player location and location after transport. Interestingly, the location after transport is the same as the finish location, but the player is not teleported.

2 Replies

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

Answer by Marks98 · Feb 16, 2018 at 06:41 PM

After all what i tryed i reported it as bug to unity, because it not working only in my code. The unity helpers writed me back. The problem is, when i tryed change the position player, the player has own update method with teleport him at the same coordinates. Only what is need to do is disable it. If i understant it correctly. Here is example of my worked code which working thanks to unity helpers. Thanks !

 void OnControllerColliderHit(ControllerColliderHit collision){
         if(collision.gameObject.name == "Dropp"){
                transform.position = new Vector3(0,0,0);
                GetComponent<CharacterController>().enabled = false;
         }
 }
 
     private void LateUpdate(){
         if (GetComponent<CharacterController> ().enabled == false) {
             GetComponent<CharacterController> ().enabled = true;
         }
     }





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 bliu886 · Feb 06, 2018 at 03:44 PM

It looks like this code on a script attached to a block (or whatever object the player is colliding with). In this case, you should do

 collision.gameObject.transform.position = new Vector3(0,0,0);

instead of

 transform.position = new Vector3(0,0,0);

to change the location of the player instead of the location of the object the player is colliding with.

Comment
Add comment · Show 3 · 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 Marks98 · Feb 06, 2018 at 04:13 PM 0
Share

If you mean change from these:

  transform.position = new Vector3(0,0,0);

to these:

  collision.gameObject.transform.position = new Vector3(0,0,0);

I tried it and this code teleport the platform called Dropp. The player is in the same coordinates. I don't know why, but when i debuging player coordinates show me good data, but nothing happened like teleport.

avatar image bliu886 Marks98 · Feb 06, 2018 at 04:24 PM 0
Share

$$anonymous$$ake sure that the scripts are attached to the right gameObjects. Is there other code that could change player's position which might be changing the position back?

avatar image Marks98 bliu886 · Feb 07, 2018 at 12:54 PM 0
Share

I am using characters assets including by unity. $$anonymous$$y script i have placed on FPSController. When i place my script on the camera, nothing happenings, because camera cannot collide with any object. I don't know what i do wrong.

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

Assigning a transform using the ray cast collider. 2 Answers

Why is Unity always adding some strange Transformations? 0 Answers

Check if another object exist in a position before respawning 1 Answer

Collision direction 2 Answers

how to move the player away when it's hit 3 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