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 CrazyNinja2000 · Jul 01, 2015 at 10:26 AM · collisionboolean

Collision not changing Variable

I have a boolean saying where a ball is going to go. When the ball hits an object, it chnages the variable and goes the other way. when it collides, the debug says it collided, but the bool isn't changed.

 using UnityEngine;
 using System.Collections;
 
 public class BallMovement : MonoBehaviour {
     float x;
     float y;
     bool d;
     Rigidbody rb;
     void Start () {
         rb = GetComponent<Rigidbody>();
     }
     void Update () {
         if (d) {
             Debug.Log ("true");
         }
         Move ();
     }
     void Move(){
         if (d){
             x = x + 0.1f;
         } else {
             x = x - 0.1f;
         }
         Vector2 v = new Vector2 (x,y);
         rb.MovePosition (v);
     }
     void OnCollisionEnter(UnityEngine.Collision col){
         Debug.Log("collided");
 
         if (col.gameObject.name == "P1C1") {
             d = true;
             Debug.Log("collided");
         }
     }
 }

the debug never says "true", and the ball doesn't change direction. I will eventually use an integer for d.

Comment
Add comment · Show 4
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 Hellium · Jul 01, 2015 at 05:37 AM 1
Share

$$anonymous$$ake sure the object collided has the tag P1C1.

Change the text of the Debug.Log line 32 by "P1C1 collided" and see if this message appear.

avatar image CrazyNinja2000 · Jul 01, 2015 at 11:23 AM 0
Share

Okay, now it is saying collided twice, even though i changed it to "P1C1 collided"

avatar image hnmikechan · Jul 01, 2015 at 11:29 AM 0
Share

both your debug lines are the exact same which could easily be confused. Are you seeing 2 'collided' messages for each collision? Change line 32 to Debug.Log("P1C1 collided") like CrazyNinja said and make sure you see that in the console.

avatar image Hellium · Jul 01, 2015 at 11:37 AM 0
Share

It's normal @CrazyNinja2000 since you have one "default" Log message saying you have collided and one Log message telling you a P1C1 object has been collided.

1 Reply

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

Answer by CrazyNinja2000 · Jul 01, 2015 at 11:49 AM

Okay, i found the problem. For the box collider, I have it as a trigger, whcih i guess made it not collide. It was colliding with other object on it's sides, P1C2 and P1C3 which were not triggers. Everything is working now.

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 hnmikechan · Jul 01, 2015 at 11:51 AM 0
Share

Glad it worked. for trigger use OnTriggerEnter

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Change Boolean with collision problem 2 Answers

triggering 3DText by collision 2 Answers

How can I tell the player is in contact with the ground, within a script associated with the player? 1 Answer

How do you trigger a collider to become enabled after the player collider isn't touching it anymore? 4 Answers

trigger is not working 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