How Much to Turn?
BlitzMax Forums/BlitzMax Programming/How Much to Turn?
| ||
I'm using minib3d and have run into this problem before. I need to know how many degree to turn(Yaw) an entity to point at another entity. I can use TFormNormal to get the normal vector location in local space so I know whether the object to point to is it to the left or right. I can use DeltaYaw to determine the exact yaw my source mesh should have in order to face the destination entity. DeltaYaw will always return -180 to 180, which makes it difficult to determine how much to turn in degrees the shortest direction. Any assistance much appreciated! |
| ||
If you do not know how to do this with included functions you could do it the "learn math"-way: if you have two vectors (two objects and their view) you can split each vector up into the its axis and do the 2d-vector calculations. Sure there are multiple ways to achieve it but just try to split it into problems you already learned to solve in school. @DeltaYaw: if the value is -180 to 180 a -30 is shorter than +40. In that case you just should check for negative ("left") or positive ("right") (there is no "left right" in a north-aligned space ... on a map you cannot say "France is left of Germany"). To see how many degrees you have to turn at all: abs(DeltaYaw(...)). Somehow I think I did not understood what your problem is exactly (concerning the mentioned functions). bye Ron |
| ||
Unless deltayaw is properly broken, that should be doing precisely what you need. |
| ||
I have successfully aimed one entity at another before, using VectorPitch() and VectorYaw(). They return the components of an absolute rotation, so you need to use RotateEntity rather than TurnEntity: 'Source:TEntity 'Target:TEntity 'Vector going from the 'source' entity to the 'target' entity. Local targetVec:Float[] = [ EntityX( Target, True ) - EntityX( Source, True ), EntityY( Target, True ) - EntityY( Source, True ), EntityZ( Target, True ) - EntityZ( Source, True ) ] Local pitch:Float = VectorPitch( targetVec[0], targetVec[1], targetVec[2] ) Local yaw:Float = VectorYaw( targetVec[0], targetVec[1], targetVec[2] ) RotateEntity( Source, pitch, yaw, 0, True )Instead of rotating the entity like above, you can subtract the global EntityPitch() and EntityYaw() values of the source entity from the 'pitch' and 'yaw' results to find the difference. |