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
0
Question by M.Qayyum · Jun 16, 2012 at 09:35 AM · first-person-controllerhit

Hit an object with other object and count hits

First person controller will hit stupms with a ball, if the ball hits the stumps then the stupms will be dismanteled and hits are recorded in count variable.

I am new to unity3d .Please help

Regards M.Qayyum

alt text

Edit: I'm able to fire a ball from First Person Controller and hit this cube but i can't able to detect that if cube is hit by ball or not.

Here is my script

 public var ballPrefab : Transform;
 
 public var ballSpeed : float = 1000;
 
 
 
 function Update () 
 
 {
 
    if(Input.GetButtonDown("Fire1"))
 
      {
 
      if(!ballPrefab || !ballSpeed)
 
        {
 
        Debug.Log("[Shoot] 'ballPrefab' or 'ballSpeed' is undefined");
 
        }
 
        else
 
        {
 
        var ballCreate=Instantiate(ballPrefab,  GameObject.Find("SpawnPoint").transform.position, Quaternion.identity);
 
        ballCreate.rigidbody.AddForce(transform.forward * ballSpeed);
 
        }
 
    }
 
 }
pic.png (382.3 kB)
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 M.Qayyum · Jun 16, 2012 at 01:44 PM 0
Share

Please any one can help

avatar image whydoidoit · Jun 16, 2012 at 01:54 PM 0
Share

We can't write your game for you, we can help with specific problems. If you are really new to Unity it would be a good idea to do one of the tutorials which will really help with your understanding of what is possible.

Do you already have the code that makes the stumps dismantle etc? If so and you just want the counting then I'm sure we can help :)

avatar image M.Qayyum · Jun 17, 2012 at 10:40 AM 0
Share

@whydoidoit I have updated the question.

2 Replies

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

Answer by whydoidoit · Jun 17, 2012 at 10:42 AM

So the ball needs a sphere collider and the cube needs a box collider. If the cube also has a rigidbody it will automatically react to being hit. tag the ball with a new tag of "ball" and the stumps with "stumps" in the inspector.

To see the collision yourself write a function :

  function OnCollisionEnter(collision : Collision) {
        if(collision.gameObject.tag == "ball"){
           //do something like increment your counter
         }
     }

That would be attached to the stumps, if you want to attach to the ball change "ball" to "stumps".

Comment
Add comment · Show 2 · 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 M.Qayyum · Jun 17, 2012 at 10:56 AM 0
Share

@whydoidoit Thanks $$anonymous$$ike Now cube is reacting after collision but i have write this line in above code Debug.Log("ABC"); and it is not detecting any collision. And i have a ballPrefab which is tagged as "ball" and i have attached this code with cube.

avatar image whydoidoit · Jun 17, 2012 at 09:06 PM 0
Share

So firstly lets just check I haven't screwed something up for you. Can you do a Debug.Log right at the top of OnCollisionEnter? See if you are every getting that?

avatar image
0

Answer by 1337GameDev · Jun 16, 2012 at 04:37 PM

Well use a first person controller script (included with unity) and then make an action for when you press the button to "fire" and then just do an collision check to see if something hits the stump (which is a prefab). Then in your script make the log dismantle when it is hit with a method call. We cannot write the game for you, but this should give some direction. I would start with video tutorials on how to set up a basic game to know the basics of unity before you delve into this. It is quite daunting. well good luck

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

swing to hit a target 1 Answer

Destroying object using his name and raycast 2 Answers

Raycast Never Hits Anything?! 2 Answers

finding vertices by distance to hit point 1 Answer

Is object at least partly visible? 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