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.

DarkBASIC Professional Discussion / Object rotate to face the same way as camera.

Author
Message
Mang Master
18
Years of Service
User Offline
Joined: 22nd Mar 2008
Location:
Posted: 25th Nov 2011 00:00
Hi,
I am having some problems on a seemingly simple issue, but it deemed to be harder to do than it looks.

I'm making a 3d platformer game and I have the camera rotating at different camera angles throughout the level, and I think that something that would help smooth out the look of the player turning. If I have the player slowly rotate to the direction that the camera is facing, it looks really nice, but for the life of me I can't figure out how to make it work. Ive tried a simple formula such as:



But that seems to half work. You see, it works if say, the camera angle was 90 degrees and the object angle was 45 degrees, then it would work by turning the object right.

But let's just say the camera angle is 356 and the object angle is 10. With my formula it would make it turn right and do an almost full turn, as the most logical thing would be just for it to turn left 14 degrees.

So my question is, what would be the best way to do this correctly?
Daniel wright 2311
User Banned
Posted: 25th Nov 2011 00:15 Edited at: 25th Nov 2011 00:18
this is what i use in my code for this, but i added a box object for the camera to be locked onto right in front on each modle i want the camera to look at.

just use limb positions of each object to drop the camera anywhere you want then point it to anything you wish.



my signature keeps being erased by a mod So this is my new signature.
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 25th Nov 2011 00:49
You need to check if the Target_Angle is more than Current_Angle+180 !

Because if yes, that means the situation you just encountered. In that case your program should make the camera turn the other way.

It may seem complicated, but it is very easy just think it through calmly, if you may get confused at some point just draw a simple circle, draw the 0-360 line (where the angle suddenly change to 0 from 360), and try angles, both current and target angles, and how you should calculate the change.

-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
Mang Master
18
Years of Service
User Offline
Joined: 22nd Mar 2008
Location:
Posted: 30th Nov 2011 09:56
Quote: "this is what i use in my code for this, but i added a box object for the camera to be locked onto right in front on each modle i want the camera to look at.

just use limb positions of each object to drop the camera anywhere you want then point it to anything you wish."


Thank you but I would rather not change my camera code now, Its working fine for now.

Quote: "You need to check if the Target_Angle is more than Current_Angle+180 !

Because if yes, that means the situation you just encountered. In that case your program should make the camera turn the other way.

It may seem complicated, but it is very easy just think it through calmly, if you may get confused at some point just draw a simple circle, draw the 0-360 line (where the angle suddenly change to 0 from 360), and try angles, both current and target angles, and how you should calculate the change.
"


Ok I have been really thinking about this, but I still don't see how this would fix my problem. Wouldn't it be the same except offset 180 degrees?

Thanks though.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 30th Nov 2011 19:49 Edited at: 30th Nov 2011 19:52
Hi there
@Mang Master.
Is something like that what you are up to ?.




I'm not a grumpy grandpa
Mang Master
18
Years of Service
User Offline
Joined: 22nd Mar 2008
Location:
Posted: 1st Dec 2011 01:32 Edited at: 1st Dec 2011 01:33
Almost! You see if the angle of the camera is -355 and the angle of the object is 5, it turns a full 360.

Thank you but there must be some way to do this right!
Daniel wright 2311
User Banned
Posted: 1st Dec 2011 01:41
Then that is something like this or close to it,this is what I would do.



my signature keeps being erased by a mod So this is my new signature.

Login to post a reply

Server time is: 2026-07-10 03:58:41
Your offset time is: 2026-07-10 03:58:41