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 WeirdDeveloping · Apr 10, 2016 at 08:45 PM · collisionerrorprogrammingnot working

Detecting Collision is not working

I Am trying to move the ball when the key "I" is pressed when making contact with the players, this is my code which is not working

 using UnityEngine;
 using System.Collections;
 
 public class KickForce : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
     }
 
     void OnCollisionEnter (Collision col) {
 
         if(col.gameObject.tag == "Player")
         {
             if (Input.GetKey ("i")) {
                 transform.Translate(Vector3.right * Time.deltaTime * 10);
             }
         }
     }
 }
 
Comment
Add comment · Show 5
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 Oribow · Apr 10, 2016 at 09:53 PM 0
Share

In theory, I see nothing wrong with your code. It's probably a setup problem. Add Debug.Log's to see, if OnCollisionEnter is getting called at all. Are you working in 2D? Does the player or the ball have a rigidbody?

avatar image WeirdDeveloping Oribow · Apr 10, 2016 at 11:32 PM 0
Share

i did use the Debug.Log, I Do not think its working to call the OnCollisionEnter and both player and the ball have a rigidbody

avatar image Oribow WeirdDeveloping · Apr 10, 2016 at 11:34 PM 0
Share

Are you working in 2D? How are you moving the player or ball?

Show more comments
avatar image JigneshKoradiya · Apr 11, 2016 at 11:40 AM 0
Share

check in inspector for both of object istrigger must be off

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Oribow · Apr 11, 2016 at 12:19 PM

"The biggest difference between manipulating the Transform versus the Rigidbody is the use of forces. Rigidbodies can receive forces and torque, but Transforms cannot. Transforms can be translated and rotated, but this is not the same as using physics. You’ll notice the distinct difference when you try it for yourself. Adding forces/torque to the Rigidbody will actually change the object’s position and rotation of the Transform component. This is why you should only be using one or the other. Changing the Transform while using physics could cause problems with collisions and other calculations." (http://docs.unity3d.com/Manual/class-Rigidbody.html)

That is your problem. You should not move rigidbody wit transform.Translate(Vector3.right * Time.deltaTime * 10); Use Forces, or now collision will be detecteable.

Comment
Add comment · Show 5 · 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 WeirdDeveloping · Apr 11, 2016 at 08:49 PM 0
Share

i have used the Rigidbody add force but still, i think its the OnCollisionEnter which is not working

Here is the script

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$ickForce : $$anonymous$$onoBehaviour {
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
 
     }
 
     void OnCollisionEnter (Collision col) {
 
         if(col.gameObject.tag == "Player") 
         {
             
 
             if (Input.Get$$anonymous$$ey ("i")) {
                 GetComponent<Rigidbody>().AddForce (transform.right * 20);
             }
         }
     }
 }
 

avatar image Oribow · Apr 11, 2016 at 09:55 PM 0
Share

What a oust the players movement? Do you use force there?

avatar image WeirdDeveloping Oribow · Apr 11, 2016 at 10:06 PM 0
Share

i am currently using transform for the player's movement which works perfectly

avatar image WeirdDeveloping Oribow · Apr 11, 2016 at 10:26 PM 0
Share

Can you just send a script?

avatar image SoraMahiro · Sep 08, 2016 at 09:16 PM 0
Share

Do you think this would have the same effect on Animations?

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

76 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

Related Questions

Teleporting a FPSController Character Instantly teleports back to the previous Position 0 Answers

Need help to understand Unity's logic or C# ? 1 Answer

OnTriggerEnter 2 Answers

I want my code to tell the AI to move from one log then back to the fire chamber and then to the other log but it just moves to the first log and doesnt do anything did i code something wrong? 2 Answers

Having referencing Problems while creating a tile brush for an editor in unity 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