playMaker

Author Topic: Object Selection  (Read 422 times)

Strangirs

  • Playmaker Newbie
  • *
  • Posts: 3
Object Selection
« on: July 02, 2023, 04:43:50 PM »
Hi guys,

I'm fairly new to Playmaker and have been watching a bunch of the tutorials and lurking in Discords so I thought I'd come here to ask for some help. Hopefully I'll be able to become more active on here!

I'm trying to make it so that if you look at a counter it will get "selected" as in highlighted. My current methodology that isn't working is in state one have a raycast with a layer mask set to the counters. If it hits (store as a variable didHit), and  send to the next state but also store the game object in a variable (objectHit). In the next state I have a deactivate game object (There is a duplciate of the object under it that will display the highlights). Deactivating the game object works but I'm stuck on figuring out how to activate it again as well as have multiple of the same counters in the game without changing all of them at once.

My thoughts is to do another raycast in the second state that sends back if it hits anything but the already hit game object and/or NULL which would activate the game object back in the first state. The issue with this is that if there is a space in between game objects it won't send the event until you get there because the raycast does not hold null values.

Is there a workaround to this or any better option?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7620
    • jinxtergames
Re: Object Selection
« Reply #1 on: July 03, 2023, 07:56:15 AM »
Hi.
Maybe set the "selected" object on a "selected" variable.

when you do raycast again and hit something, compare it to the "selected" variable.
If same do nothing, if not same reactivate the selected "selected" and then update the "selected" variable with the newly selected (this can also be null)
if null, skill setting selected.
if not null set that one highlighted

Strangirs

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Object Selection
« Reply #2 on: July 04, 2023, 02:57:52 PM »
Thanks djaydino!

I got a little frustrated and went with a different approach that seems to be working very well. In the raycast.cs action I added this line of code:

if (hitInfo.collider != null)
{
    storeObject.Value = hitInfo.collider.gameObject;
}
else
{
    storeObject.Value = null; // or set it to another appropriate value representing "None"
}

In the two states I went with a different approach and changed the material instead of activating and reactivating. In state 2 I had two game object variables being compared to each other "hitObject" and hitObject2" where I used your idea to go back if it's not equal. The raycast in state 1 stores hitObject and the raycast in state 2 stores hitObject2.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7620
    • jinxtergames
Re: Object Selection
« Reply #3 on: July 04, 2023, 06:34:26 PM »
Hi.
If you customize actions, its best to copy it and rename the class.
As when you update playmaker later on, your changes might be overwritten.

You can find also many custom actions on the Ecosystem (in case you didn't know yet)