playMaker

Author Topic: Linecast hit distance  (Read 2097 times)

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Linecast hit distance
« on: March 24, 2016, 10:26:59 AM »
I have a state linecasting between two objects to get the distance (among other things) and although the debug line is showing correctly in scene, the distance is coming out at about 0.95 which is manifestly wrong. To test, I debugged with a getdistance action, which measures to the object centre, and so will be different value, but not too far out in this particular case. It gives the distance as over 290, which is clearly the right ballpark.

I have debugged the linecast, so I know it is hitting the right object. I have it set up with a layer mask which currently holds only four objects in the scene, and the other three are well out of the way. (Edit: this is a 2d set up btw.)

What am I not getting?

Edit: To test, I made the hit object enormous, so that the distance to the hit point was about half the distance to the hitobject's centre and the hit distance came out as around a half. Is this how it's supposed to work then? The hit distance returned by the linecast2d is the ratio of the distance from the linecast start and hit point to the distance between the two object centres? i.e.:

(distance between linecast start point and hit point) divided by (distance between linecast start point and hit object's centre)

If so, that's okay, but it's very unintuitive, especially as it isn't described as such in either Playmaker or Unity docs.
« Last Edit: March 24, 2016, 11:44:49 AM by cats00eye »

LogLady

  • Full Member
  • ***
  • Posts: 150
Re: Linecast hit distance
« Reply #1 on: April 13, 2016, 04:26:26 PM »
Maybe I'm saying something totally wrong but isn't it returning a normalized value?

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: Linecast hit distance
« Reply #2 on: April 15, 2016, 07:39:02 AM »
I am not sure of what ratio (or maybe normalized value is the correct term) the linecast is returning.

I always thought it was where the hit took place between the start of the linecast and the the end of the linecast. So if the line is 70 in length and it hits an object at 35 then you would get a distance value of 0.5.

But this is just a guess that Ive been working with a tiny bit. Hopefully some expert will take the time clarify it for all of us.

Good luck with it!

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Linecast hit distance
« Reply #3 on: April 18, 2016, 09:59:37 AM »
Thanks for your answers. Yes, I think that's probably right. It's working that way, anyway, which is all I really care about!