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 lelouch_vi_britannia · May 25, 2011 at 02:45 AM · collisionraycastobjectshape

Is it better to use a Raycast or a Cube gameObject for projectile collision?

To detect collision with a projectile, is it better to use A Raycast or a primitive game object with the mesh renderer disabled? The raycast only detects collision with a single point where as using a cube or sphere will cover an entire area.

What i'm doing is putting a particle on top of the invisible cube and using the cube as trigger. Are there any draw backs with this method?

Thanks

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

Answer by Bunny83 · May 25, 2011 at 03:24 AM

It's actually no question what is better. It results in two different type of weapons (and there's no difference in how many targets you can hit with one shot).
Weapons are divided into

  • instant hit weapons (like you might know form counterstrike) that uses raycasts

  • projectile weapons

The difference is that instant hit weapons will hit the object for sure if your cursor is over an enemy. Projectile weapons need time to travel. If you plan to build a instant hit weapon but you want also a visual projectile, use a raycast for collision and a gameobject without collider just for the visual effect.

To hit multiple targets with a Raycast you can use RaycastAll. It's even possible to reduce the damage it does to the second, third,... target. You just need to sort all hits from nearest to furtherest.

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 Joshua · May 25, 2011 at 03:28 AM 0
Share

Right, but it might still be nice to actually raycast from the 'front' of a projectile weapon to make sure it doesn't miss a hit. DontGoThroughThings.JS - style :p

avatar image Bunny83 · May 25, 2011 at 02:10 PM 1
Share

Sure, ;) but if you want a real projectile weapon in most cases the speed is quite low (like arrow and bow) so you can see your projectile travelling through the air.
In Unreal Tournament the shock-rifle is an instand hit weapon but the visual beam is travelling through the air. It arrives a little bit after the real hit but that's within 50ms ;).

avatar image
1

Answer by Joshua · May 25, 2011 at 03:03 AM

Raycast will always work, but only with a single point. SphereCast always work. Using collusion detection is absolutely fine as long as things don't move at very high speeds. If the speed is too high then the collider might be in front of the target on frame x and behind the target on frame x+1 without actually ever colliding.

Comment
Add comment · Show 3 · 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 Bunny83 · May 25, 2011 at 03:13 AM 0
Share

Only a single point? what's with RaycastAll?

avatar image Joshua · May 25, 2011 at 03:26 AM 0
Share

You're right, but I meant it as not having width/height like the SphereCast(All) does, so it will only check right in front of it and disregard the projectiles width/height.

avatar image Bunny83 · May 25, 2011 at 04:16 AM 0
Share

Ah, yes, now i understand what you've meant ;)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Move object to raycast point. 3 Answers

How to get Raycast to detect collision with Object? 3 Answers

Custom Collision Detection 4 Answers

Collision Detection If Raycast Source Is inside A Collider? 4 Answers

Determining rotation for collision avoidance? 3 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