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
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.
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.
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ā¦!