• 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 Misthra-Games · Jan 13, 2016 at 04:51 AM · c#collisionbooleanphysics settings

I'm trying to make the collision work. But...

Hey. Could you look at my script and tell me why it never set "isCol" to false when its not colliding?

using UnityEngine; using System.Collections;

public class PlayerMovement : MonoBehaviour {

 private float movementSpeed = 20.0f;
 private bool isCol;


 // Use this for initialization
 void Start () {
 


 }


 void OnCollisionEnter (Collision col) {
         isCol = true;
     
 }

 void OnCollisionExit (Collision col) {
         isCol = false;
     
 }

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


     if (isCol == false) {
         transform.Translate (Vector3.down * Time.deltaTime);
     }


 
     if (Input.GetKey (KeyCode.W)) {
         transform.Translate ((Vector3.forward) * movementSpeed * Time.deltaTime);
     }

     if (Input.GetKey (KeyCode.S)) {
         transform.Translate ((Vector3.back) * movementSpeed * Time.deltaTime);
     }
     if (Input.GetKey (KeyCode.A)) {
         transform.Translate ((Vector3.left) * movementSpeed * Time.deltaTime);
     }
     if (Input.GetKey (KeyCode.D)) {
         transform.Translate ((Vector3.right) * movementSpeed * Time.deltaTime);
     }
Comment
Add comment
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

2 Replies

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

Answer by KenConrad · Jan 13, 2016 at 05:00 AM

I would guess you are colliding with something in the scene all the time, like a floor.

You could use a tag or layermask to just have it tell you if you are colliding with what you want to check.

Comment
Add comment · Show 8 · 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 Misthra-Games · Jan 13, 2016 at 05:04 AM 0
Share

There are only two objects in my scene..

avatar image KenConrad · Jan 13, 2016 at 05:15 AM 0
Share

Do both gameobjects have coliders and rigid bodies ? Are the coliders set as triggers ?

avatar image Misthra-Games KenConrad · Jan 13, 2016 at 05:19 AM 0
Share

Neither of them are set as triggers or rigid bodies .-.

avatar image KenConrad Misthra-Games · Jan 13, 2016 at 05:21 AM 0
Share

They need to be rigidbodies

http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnCollisionEnter.html

Show more comments
avatar image KenConrad · Jan 13, 2016 at 05:26 PM 0
Share

It is hard to know what you are try to do, can you describe it in more detail ? pictures ?

avatar image Misthra-Games KenConrad · Jan 14, 2016 at 04:02 AM 0
Share

i got it. All i had to do was freeze the rotation

avatar image
0

Answer by Misthra-Games · Jan 13, 2016 at 04:57 AM

Is it because my player is not a rigid body?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

66 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

Related Questions

How can I make 2D physics bounce the same as the 'multiply' bounce combine mode as seen in 3D Physics materials 1 Answer

Particle Collision between particles 0 Answers

I cant call function another script ! 1 Answer

OnTriggerEnter2D not working 1 Answer

Rotate camera on collision of character 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