• 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
Question by Aaron 1 · May 10, 2010 at 06:22 PM · dragballshootcollide

ball shooting passing through

Hi all,

I am making a cube kicking a ball. It is a side scroller game, some movements are constrained. But allot of times when the cube is moving fast he misses the ball (he goes through the ball)

Scripts:

cube:

  • Rigidbody

  • Drag Rigidbody

  • Magnitude

    var other : Transform;

    var closeDistance = 5.0;

    static var sqrLen = 0;

    function Update() {

    // square the distance we compare with if( sqrLen < closeDistance*closeDistance ){ sqrLen = (other.position - transform.position).sqrMagnitude*200; print (sqrLen); }else if ( sqrLen > closeDistance*closeDistance ){ sqrLen = (10000); print("Max reached");

    }

    }

    A look at script (for the cube to look at the ball)

    var target : Transform;

    function Update() {

    transform.LookAt(target);
    

    }

    a kick script (when I release the mouse he goes to the ball and hits it)

    function OnMouseUp () {

    rigidbody.AddForce(transform.forward *Magnitude.sqrLen);

    }

  • Configurable joint (to stop the cube from moving(z) or rotating(x))

  • On collision script to make it go back to its starting position after he hits the ball
  • Ball

    • Rigidbody
    • Configurable joint (to stop the cube from moving(z) or rotating(x,y))

    Now all is kinda working ok, except that it passes through the ball allot of times, not always. It works if he's speed is not to high but when I drag my cube further away from the ball to make it kick the ball harder it goes through it. I know it is hitting the ball because after he passes through the ball he returns to he's starting position (the On Collision script on the cube).

    I hope I made it clear what my intentions are and what is going wrong. :)

    I am rather new to Unity3d so I don't know if what I am doing is the right thing to do.

    Any help is very welcome.

    Aaron

    Comment

    People who like this

    0 Show 0
    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

    Answer by EpikOwnage · May 10, 2010 at 06:34 PM

    Havn't got time to read everything, but try this script :)

    link text

    Comment
    Tetrad

    People who like this

    1 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 Aaron 1 · May 10, 2010 at 06:58 PM 0
    Share

    Hi Epic,

    wow that was fast! :) Thanks for pointing me to that script. I tried it and it already works allot better, sadly not perfect. It always hits the ball now but sometimes it stops in front of it and hangs there :)

    Aaron

    avatar image EpikOwnage · May 11, 2010 at 02:11 PM 0
    Share

    That's an issue with RayCasting, try some tweakings

    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.

    Welcome to Unity Answers

    If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

    Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

    Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

    Follow this Question

    Answers Answers and Comments

    No one has followed this question yet.

    Related Questions

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

    Height from mouse drag speed 1 Answer

    How do I instantiate and shoot a ball along a ray cast? [ANSWERED] 1 Answer

    Drag and shoot system 1 Answer

    Why is my Rigidbody Ball not rolling on contact with Terrain? 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