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 profobaida · Aug 19, 2020 at 02:20 PM · programmingvisual studio

The character controller goes through objects

I am kinda new in Unity and I have a problem in the character controller. So I made a simple practicing game. I made a movement code for my player That is the code :

 CharacterController controller;

 public float speed = 6f;
 public float gravity = 20f;
 public float jump = 8f;
 
 Vector3 moveDirection = Vector3.zero;

 // Start is called before the first frame update
 void Start()
 {
     controller = GetComponent<CharacterController>();
 }



 // Update is called once per frame
 void Update()
 {   

     if (controller.isGrounded)
     {
         moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0f, 2);
         moveDirection *= speed;

         if(Input.GetButton("Jump"))
         {
             moveDirection.y = jump;
         }
     }

     moveDirection.y -= gravity * Time.deltaTime;
     controller.Move(moveDirection * Time.deltaTime);
 }

And I made a cube which should be the barrier the player hits and lose so I gave that barrier this code :

  private void onTriggerEnter(Collider other)
         {
             if (other.gameObject.tag == "Player")
             {
                 SceneManager.LoadScene(SceneManager.GetActiveScene().name);
             }
         }

and I made that wall's IsTrigger property true. But when I run the game the player doesn't lose and restart the scene but it goes through the barrier like it is nothing. So can you help me solve this problem? Thanks in advance.

Comment
Add comment · Show 10
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 wooolly · Aug 19, 2020 at 02:58 PM 0
Share

Is the character controllers IsTrigger property also set to true? Comment out your current OnTriggerEnter code and just add a simple debug.log("Triggered") statement to deter$$anonymous$$e whether the trigger is setup correctly.

avatar image profobaida wooolly · Aug 19, 2020 at 05:33 PM 1
Share

The IsTrigger property is set to true in both the player and the barrier. but the debug.log("Triggered") didn't print anything that means that there is a problem in the trigger right ?

avatar image wooolly profobaida · Aug 19, 2020 at 06:03 PM 0
Share

According to the API documentation (read the note)...https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html

I suggest unchecking the IsTrigger property on the player's collider and adding a RigidBody component to the player gameobject if you haven't done so already. I hope this gets the triggers activating.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by supertemich2005 · Aug 19, 2020 at 06:09 PM

I am not fluent in unity at all, i've tried it only once and it was an eternity ago, so my answer may be wrong or something, but afaik, imho, iirc and iiar(if i am right), try attaching rigid body and controlling rigid body.

Rigid body i used to make collision boxes, so your object would, well, collide, have gravity, etc.

Comment
Add comment · Show 1 · 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 Llama_w_2Ls · Aug 19, 2020 at 07:55 PM 0
Share

rigidbody and character controllers on the same gameobject is not recommended as you would have some weird movement. A rigidbody controller for your player should be designed instead or you follow some tutorials on how to set up your character controller correctly

avatar image
0

Answer by blagwedge · Aug 20, 2020 at 12:06 AM

Does the object with the CharacterController have a collider?

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

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

Multiple Cars not working 1 Answer

Peek Definition not working in Visual Studio Code for C# tokens 1 Answer

My cooldown method is not working the cube move only once then It won't move anymore 1 Answer

Project .sln Generates Incorrectly (Contains Duplicate Projects). 1 Answer

.csproj not being created 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