[SOLVED] individual raycast for instance

Hey there mind to try this:

What i noticed is that the first collision iteration of raycast (even if not in collision) is always positive while it should not.
It means that every condition to check if player is hit before getting close is always positive…and at the enemy creation they will see u anyway no matter what (or obstacles). (Like getting hit from behind a wall in Dark Souls :))
Asking if possible for a fix…simply because at an enemy creation, if laser is not hitting something, collision should not happen.
Anyway i’m asking you opinion on the matter.
I may be wrong but i remember this to works in v 5.2
Thx in advance

start the game player is hit but laser is not hitting.

you can drag black box with mouse to check collisions

u may need to get enough close to check later collisions cos i’ve volountairly reduced the lenght

EDIT: also later collisions are bad calculated, because they should not happen above laser lenght.
In the end i guess raycast collisions needs a total rework

A possible fix would be to cast the laser at declared lenght and fix the first collision

The ray cast is fine. Shape painter collision uses the bounding box not the lines. When your project starts, the variables are at their default value of 0. So, it draws a line to the top, left corner. The shape painter’s hit box is almost the size of the scene. You can use the draw collisions and hitboxes to see the hitboxes.
Collisions with a shape painter

As the lines are redrawn, the hitbox is resized.

To detect hits, you can use the raycast without testing for collisions.

It can be simplified to this: (unless you need the angle value later, the variable isn’t needed)

1 Like

I need this to chase p1 so the angle is constantly updated, i understand your second screenshot, but to me it’s not like a laser should work, if the laser is drawn by the shape painter collision boxes, it means that for example if the player is between the two enemies there is no way to avoid the collision. Thaz kinda stupid imo.
There is no point to use the laser if it works like this. It looks like the same as Square distance calculation, (but bad).
Still thanks for the clarification

Gonna replace it soon.

1 Like

You’re welcome. It’s using a distance of 100px. The ray cast is usually tested against an obstacle like a wall.

IDK if this is something more like you want?

If you want it more like a trip wire than targeting it then you could cast a ray in between the lasers and use the player as the test object. Or set the left object to test towards 0 degrees and the right to 180. You could rotate the objects and use their angle for the ray cast angle or use an object variable for the direction,

Either way. Have a good one.

1 Like

I’m gonna test it. Thx .
But at the moment i’m more oriented to use di distance between condition since it’s basically the same thing, but less complicated

1 Like

agreed, unless you’re testing against an object. Math alone is probably more efficient.

1 Like

Another question.
What if i create a laser for each object and then check for each laser.
Also do i need to link and take into account?

eg give an id to laser with the same id as the enemy.
then for each laser
if laser is in collision do something

ok nope , its not gonna work becouse the 0,0 starting pos that i dunno how to fix
(maybe giving laserx, lasery a starting point on enemy center?)

nvm, gonna post it here if i’ll find a solution.

EDIT:solved with above method, but still i don’t like how raycast works (cos it’s not a ray at all)

For needs, i’m posting the soultion here.
p1 is player, floor e is enemy, only the highlited parts are needed.

This way you can check laser collisions without issues for each instance,
The most important is the prevent laser cast condition.
It works so flawlessly now, that i’m crying.

1 Like