Pathfinding a bullet with bounce mechanism

I never come here for straight forward solution
I always expect to get something i can work with or at least someone put me on right track
And like always you just did
I was willing to try making 1st breakout game then billiard since stuff i learn from from breakout would help me make billiard game
This is more than i could ask for as a guidance so again BIG THX

1 Like

I think I see my issue. itā€™s with the new events in the newer version. I updated the GitHub version.

I was checking if the ray was hitting to the left or the right of the bounding box. It needs a little more cushion or variance otherwise it doesnā€™t trigger. A better approach might be to check both the side and top/bottom. Something like ā€œIf left of centerX and between the top and bottomā€ Iā€™m assuming the ray doesnā€™t always hit right on the edge.

project:

Edit: I need a break from this. Every time I fix one side it breaks the other side. My technique is too rigid. I need more wiggle room.

Last edit: I added some wiggle room for to the top and bottom and added a calc.status variable to track the raycast. if the raycast doesnā€™t find a wall it sets it to false and returns a position in the direction at a distance of 1,000 pixels. The new x,y can be ignored by checking the status. The action could be changed to a condition. IDK. I need a break.

Last, last edit: I updated the GitHub project one last time. I added a condition that uses the action. This way it wonā€™t trigger the action if it doesnā€™t find a wall. Iā€™m not really loving that idea but itā€™s good to have the option. I think you want to draw a line either way. Iā€™m experimenting with the condition by adding a parameter to set the variable that returns the info. I didnā€™t want to change the action because it would break it. But if thereā€™s interest, it can be changed as well.

1 Like

I didnā€™t think my question would get this much attention - thanks for the great work Keith. Iā€™ve learned a lot from this. Itā€™s been a massive help.

Iā€™m still having trouble understanding raycasting though. I wasnt sure if i should start a new topic or not and i canā€™t find a good explanation anywhere. I understand it well enough that i know how to use it to detect objects etc., but sometimes it just doesnā€™t seem to work at all, and I havenā€™t been able to figure out how to detect whether there is an obstacle in the way when searching for another object, i.e. raycasting for player, but there is a wall in the way. How do I detect the wall and stop it from detecting the player? Iā€™ve tried using multiple raycasts, but then it starts getting complicated and eventually breaks down completely forcing me to delete it all. I must be doing something wrong.

Could someone help me understand this better or point me in the right direction please?

The raycast sends a ray either using a position or angle/distance. You put the object that youā€™re testing for in the object field. If an object exists it will ā€œpickā€ the object and trigger the action. It will set the point where the ray hits the object in the optional x,y variables.

Hereā€™s the example. all objects are draggable. There are 3 block sprites, a text object and a shapePainter

Once again, youā€™ve gone above and beyond. :pray:

1 Like

I hope im not getting on your nerves with this, but i have tried and tried many different ways to make this work, and i still cant figure it out. I still have the original problem.

I got your calcbounce function to work, and i was able to use it to ā€œscanā€ 360Ā° and fire when it detects the player, but i canā€™t figure out how to make it work with more than one object at a time. Im not really sure how it even works, i just know it works if theres only one instance of it. If i duplicate it and change out the variables, it breaks it and nothing happens.

And i canā€™t figure out how to detect obstacles between two objects. I mean i can, i know how to set it up to detect the obstacle, but not in practice. I keep wishing there was some way to implement boolean logic because i havenā€™t found a way to get the equivalent of an ā€œif, elseā€ function.

For example, if Iā€™m just trying to detect a direct line of sight from an enemy to the player with no obstacles in between, my thinking would be to raycast to angle against player, if it does, raycast to player against obstacles, if none, then activate firing sequence. Otherwise, angle+1, raycast toward angle against player again, repeat 360 times. But how do i get the ā€œif notā€?? Why canā€™t i just check to see if it sees the friggin player??

I donā€™t know if Iā€™m just not cut out for this or what. Itā€™s like everything i want to do with it requires some super complicated trick that there is no guide for. It seems like this should be extremely simple, but i think itā€™s about to start causing migraines.

Edit: I had a change of thought. Itā€™s in the 2nd half. The first part is still nice to know.

I donā€™t mind. I like helping and Iā€™m still learning myself. I know the events but formulas and strategies is a different story.

How about you post screenshots of whatā€™s not working and weā€™ll see what we can do.

The raycast sends a ray like a sonar.

The one version sends a ray from one point to another the other sends a ray in a direction and diatance. Otherwise, they work the same way.

If the ray collides with an instance of the test object it triggers the condition and optionally sets the point in the optional variables.

Normally, you could invert the condition and it would work as a no object found. But with the raycast when inverted it finds the farthest instance.

As in my example to detect if there isnā€™t an object within range or between the 2 points you would need to use the NOT condition it displays as Invert. You add a NOT and put the raycast inside it.

The not inverts the result. If it detects a test object then it would normally be true and trigger the actions. But the NOT inverts it so it makes it false and doesnā€™t teugger the action.

If it doesnā€™t detect a test object it would ordinarily be false and wouldnā€™t trigger the actions but the NOT condition inverts it and makes it true and triggers the actions.

Donā€™t worry. It took me a lot of experimenting to understand instances and the NOT conditionā€¦

Edit: I had a thought after typing the first part for a different strategy. Iā€™m leaving the first part bc itā€™s still good to learn how and why it works.

If you create an object group and put the walls and the player objects inside it the you could use the group name as the test objects. You would still cast a ray between the player and enemies using a for each enemy. When it detects either a wall or player between the player coordinates and the enemy coordinates then it will trigger the action. You couuld check the groupName.ObjectName() to see if itā€™s a wall or the player. It would always detect one or the other since one coordinate was inside the player.

I donā€™t think the objectName() has itā€™s own condition. I think you need to use a compare 2 steings and use the groupName.ObjectName() expression on one side and the object name in quotes like ā€œwallā€ and another for ā€œplayerā€

Anyways, post what youā€™re stuck on and someone here will help.

If needed and I have the time tomorrow I can theow together another example.

Heres what i have now. Ive completely started over (again) and am now trying to just get them to fire at the player if there is no obstruction in their direct line of sight. This is my attempt at an if/else function since i cant find one built in.

What i dont understand is that it actually makes it to the event that rotates the enemy turret towards the player, but then it doesnt execute the very next event, fire bullet if turret is rotated toward player. I canā€™t understand why this would not activate. Like i said, Iā€™ve started over, so there are no other events that could be messing with it.

I just want the enemies to fire at the player if they can see it (no walls in between). Then Iā€™ll get to the part where if that check fails, Iā€™ll get frustrated trying to figure out how to implement the bounce line of sight check.

Perhaps i should just scrap this idea and try something this engine is more suited for since i keep having to fight it on every little thing.

Are you starting the aiFireAI timer before you check it for the first time? Itā€™s needs an intial start somewhere usually at the beginning but it depends on your needs. It wonā€™t advance until started. Otherwise, I donā€™t see anything.

Note: events are all must be true by default. The and isnā€™t needed. The & is only really useful when used with an or condition for multiple sets of conditions.

Edit: the target actions probably shouldnā€™t be under a timer. It should be able to target in realtime. Otherwise depending on how fast it rotates it might never be able to aim fast enough after waiting 5 seconds between firing.

Yeah, i started both at the start of the scene. They both work properly, the tasks move on time according to that cycle. They even rotate towards the player when itā€™s time to fire, but then they never fire. Idk. Iā€™m going to go back over a couple of your posts and then my project again shortly. I had been thinking about it so hard before i might have had tunnel vision.

edit: I updated it to simplify the drawing of the line. IDKW I thought I need to save that to the objects.

IDK if you plan on having multiple turrets but this is one way to do it. I added a shapePainter for the visuals. It helps to understand what is happening.

try it: Everything is draggable

source:

I finally figured it out in a way that first checks for direct line of sight, then checks for indirect line of sight (reflected off obstacles), and can be duplicated for multiple enemy tanks in one scene. Just have to switch out the variables for new ones for each new tank. Itā€™s complicated and tedious, but it works.

Each enemy tank has a placeholder sprite pinned to it. It is always rotating at 2 revolutions/sec.

First, during the scanning phase of the ai actions cycle, it raycasts from the enemy tank to the player against a group containing walls and the player. An invisible placeholder is positioned at the intersection. If the placeholder collides with the player, rotate the turret, fire & reset ai cycle.

Since the previous event ends the cycle if it detects the player, the next event can only activate when there is no direct line of sight.

The next event raycasts from the enemy tank to the angle of the rotating placeholder object pinned to it, testing against obstacles (walls). Another placeholder is positioned at the intersection.

It raycasts again from that new placeholder to yet another one, at the angle of reflection calculated from the incidence angle (from the enemy tank to where the first line of sight is reflected, thanks to your help Keith). Another placeholder object is placed at the end of the second line of sight. The last placeholder is checked for collision with the player, if so, fire & restart cycle.

The enemy tank basically scans its surroundings, sort of like a radar system. Iā€™ll post a picture of the events when i get home.

It would be cool if i could figure out how to save it all as an extension so i wouldnā€™t have to manually edit all of the variables for every new enemy tank, but Iā€™ll figure that out later, if itā€™s possible. Iā€™ll probably take a break and work on another part of the game for awhileā€¦!

1 Like