Log In  

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

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.

P#67698 2019-09-15 14:45 ( Edited 2019-09-15 14:47)

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.

P#67700 2019-09-15 15:42

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

P#119886 2022-10-30 23:52

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

P#119890 2022-10-31 01:25

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-12-05 22:39:48 | 0.011s | Q:17