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 / Gradually turn object to face a point in space

Author
Message
Davey B
21
Years of Service
User Offline
Joined: 22nd Aug 2004
Location:
Posted: 23rd Sep 2010 00:33
I'm trying to create the ability for ai npcs to gradually turn to face the player before intercept.

I've cracked the code to do this on the x-z plane using:



This works well for X-Z but when I adapt this code for Y plane movement to something along the lines of:



Things mess up and the objects don't face the player in the y plane properly or at all. Does anybody know what i'm doing wrong? All I want is similar functionality to the point object command, but with some realism of the ai having to gradually turn...

Thanks in advance.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 23rd Sep 2010 00:55 Edited at: 23rd Sep 2010 00:56
Ah... you're a victim of 2d rotation easiness. 3d rotations are a bigger headache - especially what DBPro uses - euler rotations.

The problem you're looking to overcome is figuring out the angle one object needs to get to to point to another object. A problem you probably would run into later on is that euler angles interpolate badly (interpolating is just going smoothly from one value to another). Usually quaternion/axial rotation is used to overcome this.

I'm sure that's a lot of new terminology. If you want, you can google rotation matrices, euler angles, and a bunch of trig stuff - this'll get you the purely mathematical solution. Another choice would be to get EZ rotate - I've heard it's really good, and you'll have a whole host of commands to use - this won't be the last time you have trouble with 3d rotation.

Uhh, I'll try to think of another way to solve this (with built-in dbpro commands and not too math-intense stuff), but I don't really know :\

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Sep 2010 01:04 Edited at: 23rd Sep 2010 01:15
I think you merely need to adjust two angles.

Try this:



Edit Actually this is better. Use the arrow keys to move the sphere:

Davey B
21
Years of Service
User Offline
Joined: 22nd Aug 2004
Location:
Posted: 24th Sep 2010 16:21
Cheers guys.

@Gandalf - that solution works perfectly, thanks very much for that!

@Neuro - Yep this isnt the first time this stuff has caught me out. You solved another problem for me a few weeks back, its a real headache all this Euler angle stuff!...

Thnx for the help
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 25th Sep 2010 09:29
Just an illustration of the problem I had stuck in my head:
http://forum.thegamecreators.com/?m=forum_view&t=176033&b=1

however what GG was doing is definitely better than worrying about tons o' rotation crap.

Gael
15
Years of Service
User Offline
Joined: 27th Sep 2010
Location: Athens .
Posted: 27th Sep 2010 17:38
If you want to calculate angles on the Common 0-360 range
try this :


distance_x=object_x-spectator_x
distance_y=spectator_y-object_y
angle_from_spectator=wrapvalue(atanfull(distance_y,distance_x))

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Sep 2010 19:37
You need two angles.

Login to post a reply

Server time is: 2026-07-23 18:58:27
Your offset time is: 2026-07-23 18:58:27