Creating a PointEntity function

Community Forums/General Help/Creating a PointEntity function

ubergeek(Posted 2009) [#1]
I've been trying to do this for a while now, and I figured this would probably be the best place to ask. :)

Simply put, how can I make a PointEntity function in a non-Blitz language? (specifically, C#)

I've scoured the internet and found quite a few different methods, but none of them work nearly as consistently as Blitz3D's PointEntity function. I assume Blitz3D was written in C++, which usually ports nicely to C#... So how did Mark do it?


GW(Posted 2009) [#2]
Can't you just get the angle to the destination entity, and then set pointing entity to that angle?


ubergeek(Posted 2009) [#3]
Well that's the problem, finding a reliable way to calculate the angle so that the first object is "pointing" at the other one.


GW(Posted 2009) [#4]
I don't understand the problem.

Entity1.Angle = ATan2(Entity1.Y - Entity2.Y, Entity1.X - Entity2.X )



ubergeek(Posted 2009) [#5]
But that's for 2D, isn't it? I need full 3D rotation...

The closest thing I've tried is this that I found in the minib3d TEntity class:
float x = target.EntityX();
float y = target.EntityY();
float z = target.EntityZ();

float xdiff = this.EntityX() - x;
float ydiff = this.EntityY() - y;
float zdiff = this.EntityZ() - z;

float dist22 = (float)Math.Sqrt((xdiff * xdiff) + (zdiff * zdiff));
float pitch = (float)Math.Atan2(ydiff, dist22);
float yaw = (float)Math.Atan2(xdiff, -zdiff);

this.RotateEntity(pitch, yaw, roll);

But the pitch and yaw values it generates are very very small (<1.00) - is there something I need to do to convert it into degrees or radians?


ubergeek(Posted 2009) [#6]
Nevermind, I fixed it. Apparently the above code resulted in Radians instead of Degrees, and the RotateEntity method I wrote assumes degrees.