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 K1kk0z90_Unity · Dec 05, 2013 at 07:22 AM · collisionraycastcolliderraycastingraycasthit

How do I check for collisions when I move objects based on Time.deltaTime?

Hi all! I'm making a Pong clone for learning purposes. I'm not using Unity's built-in Physics2D system, but I'm manually moving objects by changing their positions by a speed value multiplied by Time.deltaTime. I'm having problems with checking for collisions between the Ball and the Bats. Currently I'm using Raycasting, with Physics2D.Linecast(prevPos, newPos) method, but this ignores Ball's Circle Collider and only detects collision at Ball Sprite's center (because it casts a line between the previous position of the ball and the new position). How do I detect collision between a Circle Collider and a Box Collider 2D in a continuos way without using built-in physics? Thank you in advance! :)

Comment
Add comment · Show 2
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 iwaldrop · Dec 05, 2013 at 07:30 AM 0
Share

FWIW, this is the kind of thing that Physx is good at, but you could always use the OnCollisionEnter callback that Unity provides, and the collision data that is returned, to reflect the angle of approach.

avatar image K1kk0z90_Unity · Dec 05, 2013 at 07:34 AM 0
Share

The problem is that I'm using Time.deltaTime, so the movement is not continuos. I need to detect collisions continuosly.

3 Replies

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

Answer by K1kk0z90_Unity · Dec 08, 2013 at 10:58 AM

Thank you for your answers, but now I solved by using the Physics2D system. I still have control on ball's speed and direction, and I move it using rigidbody2D.ApplyForce(). Thank you again for your help anyway.

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
avatar image
0

Answer by Owen-Reynolds · Dec 05, 2013 at 04:03 PM

For a ball collisions, Physics.SphereCast should work (same as a Line/RayCast, except you're shooting a "thick" line.)

In general, Unity doesn't have great "at will" collision-checking. Instant code-checking a for box colliding with stuff is rough (there's no Physics.BoxCast.) Clearly, it contains all the math. But I'm guessing it's tied tightly to the physic engine, the Oct-tree, ... .

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 K1kk0z90_Unity · Dec 08, 2013 at 11:01 AM 0
Share

Thank you for your answer,but this doesn't work with sprites (I have tried it). It would be nice to have a Physics2D.CircleCast() though. :)

avatar image Owen-Reynolds · Dec 08, 2013 at 09:56 PM 0
Share

The 2D physics system is new, so will probably get more functionality later.

But, if you need to, you can always use 3D to make 2D. Just lock one axis in the rigidbodies. Then you have access to all "real" collision checks. I'd guess the specialized 2D stuff just runs faster, if you want a 2D phone game with hundreds of sprites.

avatar image
0

Answer by Spinnernicholas · Dec 05, 2013 at 04:10 PM

You can use the physics colliders as triggers.

You do this by:

 Collider.isTrigger = true;

Then you can use these messages to control when 2 colliders collide:

  • OnTriggerEnter

  • OnTriggerExit

  • OnTriggerStay

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 Spinnernicholas · Dec 05, 2013 at 04:12 PM 0
Share

Of course, you would probably want to you the 2D equivalents.

  • Collider2D

  • OnTriggerEnter2D

  • OnTriggerExit2D

  • OnTriggerStay2D

avatar image K1kk0z90_Unity · Dec 05, 2013 at 04:51 PM 0
Share

So the trigger functions work also if I'm not using the built-in physics engine? I ask because I'm not using rigidbodys and I'm moving the objects using tranform.Translate(). Thank you in advance!

avatar image Spinnernicholas · Dec 05, 2013 at 04:57 PM 0
Share

After digging deeper, one of the colliders in a collision needs a rigidbody. But you can set is$$anonymous$$inematic = false and it won't be affected by the physics engine.

avatar image iwaldrop · Dec 09, 2013 at 02:15 AM 0
Share

Is kinematic should be set to true to ignore gravity and collisions.

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

19 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 avatar image avatar image avatar image avatar image

Related Questions

Raycast Not Drawing In Target Direction 0 Answers

Raycast Collider Tag not returning correct result 1 Answer

Raycast goes through 1 Answer

Raycast exit point of collider 0 Answers

raycast not colliding 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