Course Visual Scripting / Bolt
I created another different type of enemy, which is reflectet at the walls:
The move mechanics stays the same:
Except that the distance variable has x and y values of 1 (or other values, that could be set randomly on start).
The reflection mechanics uses the following visual code for wall collisions:
With “get name” the name of the wall the enemy is colliding with is requested.
For each wall the adequate matrix for mulitplication with the distance-variable (the move direction) is selected.
By multiplication with the matrix
(1 0)
(0 -1)
the vector is mirrored at the y-axis along the x-axis (reflection top and bottom walls)
By multiplication with the matrix
(-1 0)
(0 1)
the vector is mirrored at the x-axis along the y-axis (reflection left and right walls).
(1 0
(0 1)
does no direction change.
As unity has 4x4 matrices i used these.