Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Doneyes · May 23, 2013 at 05:48 PM · collisionplayercollidewalls

Dive collide

Right now the character jumps and dives, but I need to figure out when he hits a wall or the ground. I can't check for any collider because I don't want the dive to stop if he hits a small object. Without tags, can anyone think of soem good ways to find walls?

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
2
Best Answer

Answer by clunk47 · May 23, 2013 at 06:18 PM

 void OncontrollerColliderHit(ControllerColliderHit hit)
 {
     if(hit.collider.gameObject.name == "Wall")
     {
         DoSomething()
     }
 }

OR

 RaycastHit hit;
 
 void Update()
 {
     if(Physics.Raycast(transform.position, transform.forward, out hit, 1f)
 {
     if(hit.collider.gameObject.name == "Wall")
     {
         DoSomething();
     }
 }
 }

Not really understanding your question, but try checking out the Script Reference for Raycast and ControllerColliderHit

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 Doneyes · May 24, 2013 at 10:49 AM 0
Share

I wanted to do it without any kind of "tag" but I think this will work out. I need to label my stuff anyways. How can I add multiple names and make it more efficient? Would this work?:

 col = hit.collider.gameObject.name
 
 if(col == "Wall" || col == "Ground" || col == "Crate" || )
 {
 DoSomething();
 }

I would like to make a table to store and continuously add on names to this list but I'm not sure how to go about that in this language. Is it possible?

avatar image clunk47 · May 24, 2013 at 03:28 PM 1
Share

Yes that would work, except take out that last || there.

 col = hit.collider.gameObject.name
  
 if(col == "Wall" || col == "Ground" || col == "Crate")
 {
 DoSomething();
 }
avatar image clunk47 · May 24, 2013 at 03:30 PM 2
Share

I guess || is OR, kinda how && is AND. If || doesn't work, try | I'm not sure what the difference is, I can never find any good documentation on the vertical bar character lol

avatar image clunk47 · May 24, 2013 at 03:39 PM 2
Share

You could also do an array, this example is in C-Sharp.


 using UnityEngine;
 using System.Collections;
 
 public class test : $$anonymous$$onoBehaviour 
 {
 string[] names;
      void Awake()
     {
         names = new string[]
         {
             "Wall", "Ground", "Crate"
         };
     }
     
     void OnControllerColliderHit(ControllerColliderHit hit)
     {
         foreach(string name in names)
         {
             if(hit.collider.gameObject.name.Equals(name))
             {
                
             }
         }
     }
 }
avatar image Doneyes · May 24, 2013 at 10:40 PM 1
Share

thanks for the help

avatar image
0

Answer by Bunnybomb7670 · May 24, 2013 at 11:12 AM

Look at other games and see how then do it. Looking at something like call of duty, where you can dive, if you dive at a wall, you literally collide with it and slide down the wall, just make it so that when you dive, if you have an animation, you should add a collider around the diving animation object so that if it dives into a wall, it will slide down.

Comment
Add comment · Show 1 · 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 Doneyes · May 24, 2013 at 12:28 PM 0
Share

I know what my plans are, all I needed to know was a good method of detecting a collider, but the best method after all will be giving it a tag.

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

15 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

Related Questions

Player is moving through walls when force is added from a knockback script? *UNANSWERED* 3 Answers

How to make player (sphere) shoot the ball (another sphere)? 2 Answers

Click-to-move questions 2 Answers

How to make a GameObject that collides but the player can go through it? 2 Answers

How to let the player collide with animated objects? 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