Can see object flipping raycast

wickerman

New member
Hi folks,

I'm making a 2d metroidvania style game and am using the can see object task to prevent enemies chasing the player character through walls etc. However, I'm struggling to get it to flip when the enemy turns from left to right, and it only detects the player from the left.
I can "solve" it by making the fov 360 degrees, but that's not 100% as the enemy will chase even when they are unable to see the player.

Is there a way to get it flipping so it stays consistent with the direction the enemy is facing? Or will I need to edit it in someway?
 
Can See Object will use the transforms forward direction in order to determine which way is forward. If you can't change the direction of the main GameObject maybe you cou
 
Can See Object will use the transforms forward direction in order to determine which way is forward. If you can't change the direction of the main GameObject maybe you cou
Ah I see, to flip the sprites in my game I'm using the scale of the transform as I only need to worry about the x axis, this is how they are turning from left to right and vice versa. I have managed to get it flipping with the raycast from the task also flipping by changing the rotation y axis by 180 degrees. but that forces me to leave the scales x axis alone, and my code is built around it to know what side i'm facing. I'll have to have a mess around with it. However, if you could finish your thought I would greatly appreciate it. You can't leave a guy hanging like that!
 
Hah, it didn't post correctly. I meant to say...

If you can't change the direction of the main GameObject maybe you could create a child GameObject that either the behavior tree sits on top of that does flip or create a new task that is copied from the original task and add an offset.
 
Thanks for that, I've decided to just remake it to match my needs. Also, the main driver for this is that I wanted a custom tasks I'd made to use fixedupdate as it is physics based (it moves towards the player). I was struggling to get the movement in the fixed update and still have the task actually complete. The best I had gotten was to return running or success based on a boolean and failure otherwise if a shared variable wasn't populated. I then used a conditional abort based on the shared variable. Is that the best way to handle this? Or do you know a better way?
 
That is correct for fixed update. With that said, for actual character movement I do not recommend having it within the behavior tree itself and instead have a separate agent controller that does the low level movement. This is what we do with the Ultimate Character Controller and it works out really well as your behavior tree can be focused on the actual AI rather than the locomotion logic.
 
No, you can't use the Ultimate Character Controller with 2D. I was mainly talking about the design of the behavior tree - it splits out the functionality so the behavior tree doesn't manage character controller functions.
 
So in the task i would simply call a scripts method placed on the game object the tree is on, once it's conditions are met? So for example if im close enough call enemy.attack() or something like that?
 
Yes, that's correct. Take a look at this page for an overview on how the Ultimate Character Controller integration works:

 
Back
Top