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 /
This question was closed Mar 26, 2018 at 06:10 PM by Paddy3004 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Paddy3004 · Mar 26, 2018 at 04:50 PM · physicsdistancephysics.raycastphysics.spherecast

Problems with Physics.Boxcast ( reward for fixing 10€ via paypal )

alt text

So i created this test scene to show you my problem

i wanted to detect how far my cube( for this example ) can move in a certain direction. I use Physics.Boxcast instead of raycast because raycast is way to thin.

I used Physics.Spherecast in past and it worked perfectly fine but i wanted to use Boxcast because my Object isn't a sphere

so my problem is that i get completly wrong hit.distance values and also my gizmos always show a distance betweet ground and itself for reasons i dont understand.

I want my Boxcast to go all the way down to the ground or the wall and give me the right hit.distance value

If you can fix my problem you can send me a email with your paypal data after and i give you a small donation, because you really don't find much about this on the web.

and a screenshot of my scene

using System.Collections; using System.Collections.Generic; using UnityEngine; public class testscript : MonoBehaviour { public float maxDistance; public LayerMask layerMask; private Vector3 origin; private Vector3 direction; private float currentHitdistance; void Update () { origin = transform.position; direction = Vector3.down; RaycastHit hit; if (Physics.BoxCast(origin,new Vector3(1,1,1),direction,out hit, Quaternion.LookRotation(direction),maxDistance,layerMask,QueryTriggerInteraction.UseGlobal)) { currentHitdistance = hit.distance; Debug.Log(hit.distance); } } private void OnDrawGizmos() { Gizmos.color = Color.red; Gizmos.DrawWireCube(origin + direction * currentHitdistance, new Vector3(1,1,1)); } }

scre1.png (358.5 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 RobAnthem · Mar 26, 2018 at 04:57 PM 1
Share

I don't care about the donation or whatever, but I am curious, what do you mean it is giving improper distance? You are aware that it gives the distance traveled, correct? Which means your box having halfextents of 1, makes the box size 2, and as such, the box will never calculate the distance to the center of the box, but the first edge of the box that touches the terrain. So automatically this will be a $$anonymous$$imum of 1 meter away.

avatar image Paddy3004 RobAnthem · Mar 26, 2018 at 05:13 PM 0
Share

thank you i didnt knew this

also did it just delete my first reply, i am knew at this forum

avatar image Paddy3004 RobAnthem · Mar 26, 2018 at 05:53 PM 0
Share

fuck i didnt knew this thank you i feel like the biggest idiot right now guess i just have to add half the rest amount then, thank you

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by taylank · Mar 26, 2018 at 05:12 PM

When you use Vector3(1,1,1) with BoxCast, that's the half extents of your box, so your real box size is assumed to be 2,2,2. Whereas with DrawWireCube the argument you pass is size, which is the whole length of an edge. So you are visualizing two mismatched lengths.

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 Paddy3004 · Mar 26, 2018 at 05:14 PM 0
Share

thank you i didnt knew this,

avatar image Paddy3004 · Mar 26, 2018 at 05:32 PM 0
Share

do you want you reward?

avatar image taylank Paddy3004 · Mar 26, 2018 at 05:38 PM 1
Share

Don't worry about it. :)

avatar image Paddy3004 taylank · Mar 26, 2018 at 06:09 PM 0
Share

oke then i will close this thread :)

Follow this Question

Answers Answers and Comments

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

Related Questions

Is there a limit on the distance of raycast? 2 Answers

Physical shots 3 Answers

Physics.Raycast lagging behind 1 Answer

Physics.SphereCastAll Gives Inconsistent Results 2 Answers

iam using raycast.hit function.am trying to move vehicle over the terrain ups and down?? 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