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 /
  • 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.

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

Unity3d OnCollisionEnter not firing 1 Answer

Advance Colision Detection 1 Answer

How can i restart a script on collision ? 1 Answer

Check through array list 1 Answer

how do i collide and kill the enemy while pressing space Unity 5 C# 2 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