How to make enemy go back and forth in a platform with edges(No walls) using raycast.
The enemy should move on the platform without falling down. But in my implementation the enemy falls down when going through left edge and moves back and forth very fast(jittering) when on the right edge. So the start is there just need to make it work without any issues.
First and foremost, under Raycast_method get rid of “Repeat for each”. It is doing nothing here (except adding to processing time).
Events work on all instances by default. Conditions filter the instances out - so “Enemy is on floor” will make it so the event will only work on those Enemy which fulfill the condition. In this case none of the actions need to be different for the Enemies that are being picked. For example, all of the Enemy with Dir = 1 will get a positive X force. There’s no need to go through each of them… if five Enemy have Dir = 1, you are giving the same force to all five.
The top part where you are giving a random Dir however, does need a For Each, but it should be reordered to filter first
Variable Dir of Enemy = 0
-> Repeat for each Enemy
<empty condition> | do stuff
Now, as for the actual issue of preventing them from going off ledges, it seems like your implementation might work but the problem (I think) is that you used the same angle of 270 for both sides. I’m not really sure why it is 270, which is directly up? Should probably be 45 (down and to the right) and 135 (down and to the left). Also, I don’t think you need the offsets like CenterX() - 8… raycast will only find the “against” object (NewTileMap), so you can probably just use CenterX() and CenterY()
Why are you using a raycast? And why the +10 and -10 on the Y position of the raycast? That’s just changing the height of where the raycast starts.
I’d suggest a better and more efficient method:
Add a point to the enemy sprite that’s in front (i.e. to the right) and a little below the enemy sprite’s collision box. Then in the events check that the point is still in a floor object and turn the enemy around if they’re not.
I wonder would Homlessdev be willing to come here and say same thing to you
Anyway Homlessdev did not explain to Peace anything
And left him with problem
I decided i gonna wait for him to give at least some help to Peace but seems that didn’t happen
And now i see this topic
But funny part is raycast would totally work
And what is even better you don’t need to create points but just offset object center point for example
Not expecting here anything
You was confused why raycast and that was whole story behind it
Hey thank you all for replying. I fixed the problem on my own I just forgot to check here as I was implementing the logic for the jam so I didn’t have much time to check the post but again other’s can come across this post and fix the issue if it ever occurs for them. I’ll also look into your approaches and learn from it. Thank you once again.