playMaker

Author Topic: Raycast 2D doesn't flip with object  (Read 684 times)

rizenmusic

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 10
Raycast 2D doesn't flip with object
« on: March 10, 2021, 01:10:24 AM »
Hi! Can't figure out how to resolve this. I need my enemy to detect platform edges. For this I created an empty gameobject near it to check for ground and if false then multiply it's speed to -1 and flip sprite.

But when I'm near the edge and the bool returns false, flipping function fires, objects are where they need to be, but raycast is in it's previous place like this:



It then returns loop count exceeded error.

My settings are this:







It's very easy to implement via code and it worked perfect that way but I need fsm for enemy AI so I chose Playmaker for that matter. What it's wrong?

Thanks.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Raycast 2D doesn't flip with object
« Reply #1 on: March 10, 2021, 06:40:29 AM »
Hi.
in our game i have a empty object in front of the AI character, this character is set as a child to the sprite renderer (which is not set as root, my root has a rigidbody2d and a collider for floor collision)
the empty object i use for raycast source position.
i use set rotation and set the Y rotation 0 / 180

So it looks similar to your setup.

but my raycast point is just above the ground (and doing a raycast downwards and one forward (for checking walls)

and while writing this i noticed that you raycast 'Space' is set to 'World' maybe that's the issue.
it should probably be 'Self'

I also noticed you are setting positive/negative velocity.
There is an action called Set Forward Velocity 2D on the Ecosystem

rizenmusic

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 10
Re: Raycast 2D doesn't flip with object
« Reply #2 on: March 11, 2021, 05:17:48 AM »
World wasn't the problem. The problem was that I didn't need to change my enemy speed (why?) because it moves totally normal with positive speed on both directions. I don't know why is this honestly because how can it move to -x velocity using positive speed? Is this intentional?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Raycast 2D doesn't flip with object
« Reply #3 on: March 11, 2021, 07:37:11 AM »
Hi.
Your Velocity Is set to 'Self' which means if you rotate it, it will go to that direction.
So it depends on the Rotation of the object.
If set to 'Word' its dependent to world space.

I think this is only recently added (Pm 1.9.1) to the 'Set Velocity 2d' action.
So if you set to Self it works the same as the Action "Set Forward Velocity 2D" i mentioned on my last post.

rizenmusic

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 10
Re: Raycast 2D doesn't flip with object
« Reply #4 on: March 11, 2021, 08:37:34 AM »
I've spent half a day trying to figure it out and now it's finally clear :) Thanks a lot!