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.

Dark GDK / Rotate to face a point (such as the player)

Author
Message
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 15th Dec 2007 02:51
How do I rotate an object "towards" a player? That is to say, if the object is at <x,y,z> and the player is at <a,b,c> and they're both facing arbitrary directions, and I want to use the object.rotatePitch(.1) OR object.rotateYaw(.1) OR object.rotatePitch(-.1) OR object.rotateYaw(-.1), and I have to pick the one of those four that results in the least amount of rotation required to face the player, how would I go about doing that?

Thanks

--aersixb9
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 15th Dec 2007 04:33
Bro - when I was working on this space project - I never finished - um - there was this code I found somewhere where this guy wrote some code using just sin and cos - and lots of multiplication.

I won't pretend to understand how it worked - but I did manage to get it working.

There were like a bunch of baddies and they would all "believably" turn and fly toward ya from anywhere - it reminded alot of how Star wars fight scenes looked in the movies!

I'm willing to give you the code I have (I don't know the original guy's name off hand - but I did implement it and it did work.)

It doesn't use vectors and all that - (I dont think) but its sweet.
(Haven't scope out the source in awhile - though while writing this I took a stab at getting it all to compile - I think I just need to move some media around etc - and I could probably put together a little "project Zip for ya if you want. It may have a clue on what you're trying to do.

It has some terrrain - a planet that hovers in the sky - you start in your ship - then eventually - the bad guys find ya - and you hear them fly by and stick around ya - and you can fly backwards so you can watch em go after ya - its really cool looking - nothing to fancy - but amazingly smooth AI - wasn't me who wrote that part - I did everything else - except the wispy clouds - I got that from a snippet here somewhere.

tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 15th Dec 2007 05:04
You need to calculate the angle between two vectors, then use that angle to turn that amount.

The angle between two vectors is given in this formula:

angle = acos( v1 • v2 )

That is v1 DOT PRODUCT v2, not times (multiplication). The dot product is a math function available in DarkGDK.

v1 would be the vector from one object to another (from the player to the object) and v2 would be the players current facing vector.

To find out which way to turn you have to use vector projection.




Here is some code I wrote for another project (not using DarkGDK but still using C++/DirectX)




There are lots of resources about this online if you search for "angle between two vectors" and "vector projection".
The Mayflower
16
Years of Service
User Offline
Joined: 17th Dec 2007
Location: Plymouth, Massachusetts
Posted: 18th Dec 2007 00:51
Lol simple. I made a post about rotating around objects and pointing to them.

Use dbPointCamera()

Login to post a reply

Server time is: 2024-10-08 18:15:10
Your offset time is: 2024-10-08 18:15:10