Log In  


Cart #lookat-0 | 2019-09-15 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

Made this little cart as I was working through coding a look-at type function. Wanted to post it in case it's helpful for someone.

This type of functionality is useful for all sorts of things. Maybe you just want one character to look at another or a gun barrel to follow the cursor etc.

1


Strangely last night I was thinking of the Apple ][ game called "RobotWar."

What's especially interesting about this game outside you have the ability to write code for your robot to battle other robots is its unique ability to SEE other robots.

And I don't just mean diagonally or from a cross +, no, you could rotate the head of your robot and if you were within range of both your sensors and angle, you could indeed see your opponent and react thusly.

Just me guessing the easiest way to do this would be for the computer to determine the angle to the other target and then get an ABS() for the angle of the "head" of the first target (player) and get a number from 15 or less so even if its not in perfect sight, it can vary a bit.

Also to check distance. Too far and the robot cannot see the opponent.

What would especially be interesting, PL, would be to add walls, both horizontal and vertical, and be able to be blocked by attempting to look through this solid object.


doesn't the atan2 function recieve arguments as first y then x? that's weird


pico-8 trig has its own conventions. type help atan2 in the command prompt for all details!



[Please log in to post a comment]