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 TheRedGuy90 · Apr 21, 2016 at 04:46 AM · collisionphysicsoncollisionenter

OnCollisionEnter Trigger

I am creating an OnCollisionEnter trigger, but having syntax trouble.

if I want OnCollisionEnter to stop transform.translate, how do I write that?

OnCollisionEnter; transform.translate(0,0,0)

I read the documentation, which wrote OnCollisionEnter as a void, however I get an error regarding the 'void' part.

Comment
Add comment · Show 3
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 Namey5 · Apr 21, 2016 at 09:13 AM 0
Share

Surely you should use OnTriggerEnter?

avatar image TheRedGuy90 Namey5 · Apr 21, 2016 at 11:24 PM 0
Share

I didn't think about that.

...And don't call me Shirley.

avatar image Soraphis · Apr 21, 2016 at 10:42 AM 0
Share

for the "void" part: make sure you use C# for the stop "transform.translate": we need a bit more information here, if you translate you objekt in the update method a simple "transform.translate(0,0,0)" in the OnCollisionEnter/OnTriggerEnter will not work

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cepheid · Apr 21, 2016 at 12:55 PM

Hi there @TheRedGuy90

It's pretty plain to me here that you're probably misunderstanding what OnCollisionEnter is. OnCollisionEnter is a method and thus cannot be used as a statement. To use the OnCollisionEnter method you must define the method within your class and then perform the statements within it, for example:

 void OnCollisionEnter (Collision other)
 {
       transform.Translate(0,0,0);
 }

That will now check for a collision and then stop the player's movement when they collide with an object. If this does indeed sound like the problem you were having I would highly recommend you pick up a beginner's book on C# before attempting to go any further otherwise it's going to be an uphill struggle.

I hope this helps!

Comment
Add comment · Show 4 · 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 TheRedGuy90 · Apr 22, 2016 at 09:51 PM 0
Share

Parsing error: $$anonymous$$ember names cannot be the same as their enclosing type

avatar image Cepheid TheRedGuy90 · Apr 22, 2016 at 10:26 PM 0
Share

Could please post the entire class that is causing this problem? The error you have shown is occurring because you have named the method the same name as the class. Please ensure that your class name is seperate from the OnCollisionEnter() method. For example:

 using UnityEngine;
 using System.Collections;
 
 public class Exampleclass : $$anonymous$$onoBehaviour
 {
     void OnCollisionEnter (Collision other)
     {
         transform.Translate (0, 0, 0);
     }
 }
avatar image TheRedGuy90 Cepheid · Apr 23, 2016 at 06:04 PM 0
Share

I changed the name of the class, which fixed it.

But the script does nothing so far. I would like my character (which the script is attached to) to recognize this when it runs into any collider. I'd like to get rid of Unitys physics, I'm having too many problems with it, so I am writing my own.

Show more comments

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why/How 2d tower of blocks collapse? 0 Answers

Friction affects ball's direction after collision 0 Answers

Physics Movement without Physics Reactions 1 Answer

Collider fires consistently, but Trigger does not? 0 Answers

Is there a way to limit animation on collision? 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