Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Getting Dizzy

Author
Message
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 2nd Nov 2012 23:02
So, I have this math issue giving me a problem.

My variable "Facing" returns the character's facing direction. (1,2,3,4 is Right,Down,Left,Up respectively)
I need the character to slowly rotate to face that direction in 90 degree angles. This is adequately accomplished using this portion of the code:



The problem is, since the object's angle is dependent on facing, the rotation flips the wrong way when it crosses 4, that is to say, it will always rotate correctly except turning from right to up or vice-versa. I thought "IF (b-a)>180 THEN INC b,360" would fix it but it effectively does nothing. That's when I implemented "IF (b-a)>180 THEN b=b-360". Now it can turn TO 4 correctly, but turning from 1 to 4 still messes up, and it returns negative angles (which is perfectly fine, I just don't want to get angle numbers that are too large.)

Here's the rest of the code so you can all test it.

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 4th Nov 2012 12:50
Have you heard of EZRotate?

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 4th Nov 2012 20:19 Edited at: 4th Nov 2012 20:32
Sometimes the best way to explain how to do something, is to explain it in code:



If I were you, I would scrap your movement code and use my snippet as the basis; just store your properties in your UDTs and reference them accordingly.

Note that the code does not use Matrix1 commands, which you could use to reduce down.

Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 5th Nov 2012 00:47
Thanks Chris. What I'm trying to do is something like a 3d, 3rd perspective, grid-based rogue-like-dungeon sorta thing. I got it to return a facing value from your code now I need to figure out how to move it again. XD


@MrValentine: Yeah, but I kinda like 3d Math.

Login to post a reply

Server time is: 2024-03-28 17:59:57
Your offset time is: 2024-03-28 17:59:57