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 /
avatar image
0
Question by deeredman1991 · Jul 11, 2011 at 08:12 PM · c#collisionaxisignoreignorecollision

Why does my player object decide to ignore colliders whenever he feels like it? c#

ok here is my code for X movement...I'm making a sidescroller...I know the collision is taking place because I have an on collision event that stuns the player...but he just decides to ignore the collider of the bandit and thin walls...however I can't make the collider on the bandit any bigger because he is only so big...here is my codes

This one handles x movement and is located in the Update() function

 float wx = Input.GetAxis("Horizontal") * Time.deltaTime * curspeed;
 if(isstuned == 0)
     {
 transform.Translate(wx, 0, 0);
 }

this is the one that handles collisions this is taking place...but for some reason he is not getting knocked back or stopped...(I don't think its the knockback code going the wrong way because it was ignoring collisions before I put this in)

 IEnumerator OnCollisionEnter(Collision  collision)
 {
     //with bandit
     if (Time.time>nextDmg && collision.gameObject.tag == "Bandit")
     {
         nextDmg = Time.time + noDmg;
         //if bandit is to the right
         if (Physics.Raycast(transform.position,Vector3.right,10))
         {
             //take controls away from the player
             isstuned -= 1;
             //knock player to the left
             rigidbody.velocity = -transform.right * knockback;
             //minus 10 hp, and then print to console for debugging
             hp -= BanditDmg;
             print("-10 hp struck by bandit from the right"); //debug
             yield return new WaitForSeconds(1);
             //give controls back to the player
             isstuned += 1;
         }
         //if bandit is to the left
         if (Physics.Raycast(transform.position,Vector3.left,10))
         {
             //take controls away from the player
             isstuned -= 1;
             //knock player to the right
             rigidbody.velocity = transform.right * knockback;
             //minus 10 hp, and then print to console for debugging
             hp -= BanditDmg;
             print ("-10 hp struck by bandit from the left"); //debug
             yield return new WaitForSeconds(1);
             //give controls back to the player
             isstuned += 1;
         }
             
     }

 }
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

1 Reply

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

Answer by sneftel · Jul 11, 2011 at 08:21 PM

It's possible that the collision is occurring but neither of those raycasts is succeeding (because you're only doing a raycast from a single point). If you want to check which side the bandit is on, just compare the player's x-position with the bandit's.

Comment
Add comment · Show 9 · 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 deeredman1991 · Jul 11, 2011 at 08:26 PM 0
Share

how would I go about doing that? lol

cause that's what I originally wanted to do...but I couldn't do it cause I didn't know how so I just had to use a raycast lol

avatar image sneftel · Jul 11, 2011 at 09:08 PM 0
Share

well, you clearly understand how to access a Transform component; the position can be accessed as transform.position, and the x component specifically can be accessed as transform.position.x.

avatar image deeredman1991 · Jul 11, 2011 at 09:14 PM 0
Share

yeah...but how do you access the transform.position.x of the bandit from the player script? lol "gameObject.tag == "Bandit".transform.position.x" maybe?...but wouldn't that change the position of all the bandits and not the specific bandit I am trying to bounce named bandit1?

avatar image sneftel · Jul 11, 2011 at 09:22 PM 1
Share

I suggest you look at the documentation for the Collision class. It kind of sounds like you're treating things like gameobject.tag == "Bandit" as magical incantations. Getting to know the objects you're using will help you out a lot here.

avatar image Chris D · Jul 11, 2011 at 10:09 PM 1
Share

@deeredman1991 try looking through the highest rated questions on the site; they're pretty helpful and the first result is a huge list of tutorials. Additionally, just search "tutorials" here or "unity tutorials" on google and you're golden.

http://answers.unity3d.com/index.html?sort=votes

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Instantiated Projectile IgnoreCollision Error 0 Answers

How to detect if collisions are being ignored unity 2018 2 Answers

Collider not continuing to Ignore CharacterController after center changes. 0 Answers

Alternatives to physics.ignorecollision() to ignore 2d collisions 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