playMaker

Author Topic: Cant get raycast to point at right direction[SOLVED]  (Read 6150 times)

Demonocrat

  • Playmaker Newbie
  • *
  • Posts: 14
Cant get raycast to point at right direction[SOLVED]
« on: December 11, 2012, 04:47:35 PM »
Hello!
I'm kinda stuck here with pretty trivial problem =)
I need to create raycast from object to the player to see if there is anything at all between them.
I take players position v3 and store it in variable then i set this vriable as direction for raycast projecting from the object.

And for some reason i have this:


As you can see by debug line that raycast is pointing everywhere but in direction of player (construction guy).
I think that i shouldn't use transform.position of the player for direction here, but what should i use then?
« Last Edit: March 18, 2013, 09:24:05 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Cant get raycast to point at right direction
« Reply #1 on: December 11, 2012, 04:55:54 PM »
Hi,

 The position of the player is NOT its direction. Do you understand the difference? the position represent "where" it is in the 3d space, while you actually want to know where it looks.

 so to rayCast properly, you need both the position of the ray AND its direction.

so, set the "from position" to the position of the user.
then you need to set the direction value:  if you want to raycast in the z axis direction of the player, you will need to input in the direction "Vector3(0,0,1)"
 
Does that make sense?

bye,

 Jean

Demonocrat

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Cant get raycast to point at right direction
« Reply #2 on: December 11, 2012, 05:21:04 PM »
Hi,

 The position of the player is NOT its direction. Do you understand the difference? the position represent "where" it is in the 3d space, while you actually want to know where it looks.

 so to rayCast properly, you need both the position of the ray AND its direction.

so, set the "from position" to the position of the user.
then you need to set the direction value:  if you want to raycast in the z axis direction of the player, you will need to input in the direction "Vector3(0,0,1)"
 
Does that make sense?

bye,

 Jean


Hi, Jean!
I really, really want to understand it, but fail at it for now =(
That's how i thought raycast work - i set starting point (game object or position) and another point through with ray should pass (direction) and line is drawn through two of this points. Seems like its not so easy ))

I tried to do what you told me, but somehow i think i understood you horribly wrong, course setup i got make no sense (and result) for me at all.
(see pic below)


It didnt work (obviously) since i dont get in what form and where should you reference the player in raycast setup.

I'm sorry for being dumb =)

« Last Edit: December 11, 2012, 05:23:34 PM by Demonocrat »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Cant get raycast to point at right direction
« Reply #3 on: December 11, 2012, 05:25:22 PM »
Hi,

 from your screenshot, I don't see any info or event going out of the raycasting. This may now be the problem.

bye,

 Jean

Demonocrat

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Cant get raycast to point at right direction
« Reply #4 on: December 11, 2012, 05:30:07 PM »
Hi,

 from your screenshot, I don't see any info or event going out of the raycasting. This may now be the problem.

bye,

 Jean

There should be no event, this is test object on infinite loop. Point of screenshot is that with this setup there is no visible raycast at all =)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Cant get raycast to point at right direction
« Reply #5 on: December 11, 2012, 05:33:04 PM »
Hi,

 you need a way to get out of this loop if something is hit, then you can come back to hit after you have processed it. else, I am not sure what's your use of the raycast and how you will use it's infos.

bye,

 Jean

Demonocrat

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Cant get raycast to point at right direction
« Reply #6 on: December 11, 2012, 05:42:29 PM »
Hi,

 you need a way to get out of this loop if something is hit, then you can come back to hit after you have processed it. else, I am not sure what's your use of the raycast and how you will use it's infos.

bye,

 Jean

I have a proper FSM for enemies with events. I created this cube just to find a way to create raycast pointing at my character. No luck yet ))
I created event that not happening for a proof:


Stuck at state 1 still ))

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Cant get raycast to point at right direction
« Reply #7 on: December 11, 2012, 05:43:59 PM »
Hi,

 you do need to set the "Hit event" to the event "I worked!" of the rayCast action actually, else it will not trigger by itself unfortunatly :)

bye,

 Jean

Demonocrat

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Cant get raycast to point at right direction
« Reply #8 on: December 11, 2012, 05:48:15 PM »
Hi,

 you do need to set the "Hit event" to the event "I worked!" of the rayCast action actually, else it will not trigger by itself unfortunatly :)

bye,

 Jean


But i dont want him to work on any hit... I added a check for tag of object that got hit.

Funny thing though. It woulnt work even with event set on "Hit event"


There is clearly something wrong with how i set direction value. I dont believe it could point at player when its position is not even mentioned in raycast settings.

Demonocrat

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Cant get raycast to point at right direction
« Reply #9 on: December 12, 2012, 09:24:19 AM »
I made it!!!

If anyone interested here is how to make this thing work:

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Cant get raycast to point at right direction
« Reply #10 on: March 05, 2013, 12:47:23 PM »
Thank you so much for this.

I've been avoiding using the raycast action itself because it seems almost broken in it's limitations (being able to just tell it to raycast to a position or object would be a nice change to it instead of having to do all this higher-end math stuffs which i know i don't have the brain for.)