Weekly Updating 3: Turn, Turn, Turn.

snapman's picture

I have an incredibly good excuse to not update this week, but I'm going to go through with an update anyway. It's going to be short.

Last week I got a comment linking me to the KnP tips & tricks thread here on Glorious Trainwrecks. One of the last posts in that thread was about making an object turn towards another object or direction. I remembered asking that very question of the KliK Kommunity a long time ago, and receiving almost the exact same answer: later Clickteam products have the direction calculator, which solves the problem entirely.

Not content with this, I decided to finally solve that problem in KnP. I got out some paper, sketched out the problem, and found a simple solution. I knew there were 4 situations. The first two were obvious: If the target angle is greater than the current angle, add to current angle (and vice versa). The second two were difficult. Under what situation should you subtract to get a larger number, or add to get a smaller number? What was the difference between moving from 12 to 20, and 4 to 28? The difference was, unsurprisingly, the difference. Once the absolute value of the distance between current and target grew greater than half the circle, it made more sense to loop around 0 instead. A bit of figuring, and voila! Turn Towards accomplished in KnP.

Note that this technique alone only works for one object, not a swarm of objects, because direction retrieval doesn't know which object pair to select from and give to. But that's a whole 'nother article. "Object selection" is one of the most confusing aspects of KnP event writing. Sometime I'll talk about that in greater detail. But for now, here is an example of a basic turn towards effect. Enjoy!

AttachmentSize
rotate.zip31.41 KB

Comments

kirkjerk's picture

wow, that's some really good

wow, that's some really good thinking!

I might try and make a version of Heatseeker, this old Compute's Gazette game, using this idea...

pensive-mosquitoes