playMaker

Author Topic: Raycast2D at a game object instead of direction  (Read 4057 times)

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Raycast2D at a game object instead of direction
« on: November 18, 2019, 05:54:03 AM »
Hi,

I've searched the forum and googled a bit on this action that do not seems to exist.

A lot of the time I would like my Raycasts2D to to try to hit another game object in the scene, like a very simple line of sight. Right now I always just put a "look at-action" and then raycast from that game object but I feel like this is such a common usage of the raycast that I feel like it should be a integrated part of the standard action. An option to either use "Direction" or "Gameobject" when declaring where the raycast should be cast.

Maybe this is not the case because there is a solution already (using the look at as I described) but I would the updated action.

(Maybe this should be in the Suggest action subforum and not in the help?)

/Christian

ransomink

  • Playmaker Newbie
  • *
  • Posts: 44
Re: Raycast2D at a game object instead of direction
« Reply #1 on: November 19, 2019, 02:19:18 PM »
A raycast is essentially a laser beam fired towards a specific direction. It is an API method in Unity, so it's not Playmaker specific. If you want to raycast at a game object I'd continue to use the Look At action to point toward the game object and cast in that direction. Or you can get the target game object's position, find the direction by subtracting the target position from the origin, then cast in the resulting direction. There are other methods as well

I can see a custom action with an option to supply a game object. it would get the direction using the supplied game object and the origin position...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Raycast2D at a game object instead of direction
« Reply #2 on: November 21, 2019, 02:02:13 AM »
Hi,

You are right, there are no actions ( as far as I know), that deduce the direction to shoot a raycast from a target.

Your Look at trick is good in my opinion, I would stick to it actually, because it gives you more control in the end.

Is it your typical need where you want your player to fire towards the mouse?

Bye,

 Jean

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Raycast2D at a game object instead of direction
« Reply #3 on: November 21, 2019, 09:45:53 AM »
Hi,

You are right, there are no actions ( as far as I know), that deduce the direction to shoot a raycast from a target.

Your Look at trick is good in my opinion, I would stick to it actually, because it gives you more control in the end.

Is it your typical need where you want your player to fire towards the mouse?

Bye,

 Jean


Hi,

I see. No, this is a 2d platform game and the 2d raycasts are often from the enemy to see if the player is in line of sight. So this is not a big issue, I was just curious if there was an 2-in-1-action that did the trick or if anyone else had the same request.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Raycast2D at a game object instead of direction
« Reply #4 on: November 22, 2019, 02:31:57 AM »
Hi,

 uhm... how many enenmies do you have? lookat is expensive, so in your case, it might make sense that I create a custom actions so that you don't waiste perfs on that.

Bye,

 Jean

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Raycast2D at a game object instead of direction
« Reply #5 on: November 22, 2019, 04:10:15 AM »
Hi,

 uhm... how many enenmies do you have? lookat is expensive, so in your case, it might make sense that I create a custom actions so that you don't waiste perfs on that.

Bye,

 Jean

I guess that would be nice if you have the time. But I do not have a lot of enemies tbh, but I feel like the custom action would be very welcome for a lot of people

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Raycast2D at a game object instead of direction
« Reply #6 on: November 26, 2019, 03:00:48 AM »
Hi,

 I decided to go for a dedicated action that will give you the direction ( 3d or 2d) in world or local space between two gameobjects, which means this action will work for all actions in need of a direction, that's better than making copies of raycasts actions just for this.

the action is on the ecosystem, it's called "GetDirectionBetweenGameObjects"

 Let me know how it goes!

Bye,

 Jean