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 / Making the object understand how much it should rotate based on the target position

Author
Message
jontepd
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: Sweden
Posted: 9th Mar 2009 16:13
In the code i have, i have an object (a tank) which moves to where you right click with your mouse. However a tank can not move sideways so for example if the tank is going far to the left, but not up or down at all, it needs to rotate 90 degrees before it moves. If it's going up and a little to the right the rotation is different. How do i make the object understand how much it is supposed to rotate based on the target position?

silenus
15
Years of Service
User Offline
Joined: 4th Mar 2009
Location:
Posted: 9th Mar 2009 16:33
lets say target position is x=200 z=500
Your position is x=500 z=900
your x minus target x is 500-200=300=delta_x
your z minus target z is 900-500=400=delta_z
the angle is than: dbTAN(delta_x/delta_z)
AlexZinn
15
Years of Service
User Offline
Joined: 17th Feb 2009
Location:
Posted: 9th Mar 2009 17:18
em... if its a 2d game... to get angle the only wait its use tan-1

i making now a library that makes it good for 2d..

you need the distance from mouse to the tank..(Y) divide the distance of the mouse from tank (X) and tan-1.. it is in the math.h library..
atan(x)

If someone need something, add me to your msn
Was SuperKid , now AlexZinn
jontepd
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: Sweden
Posted: 9th Mar 2009 17:56
I'm a bit unsure how to use the dbTAN thing, would be great with some help. This is what i have so far but it's not working (no conversion from 'float (__cdecl *)(float)' to 'float')

AlexZinn
15
Years of Service
User Offline
Joined: 17th Feb 2009
Location:
Posted: 9th Mar 2009 18:29
first of all i dont talking about dbTan we need tan-1
try this


#include <math.h>
alpha1 = altan(x);
alpha2 = (2,(alpha1* 180) / 3.14);

so if X = -1
alpha1 = -0.78538 (radians so)
alpha 2 = -45

If someone need something, add me to your msn
Was SuperKid , now AlexZinn
jontepd
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: Sweden
Posted: 9th Mar 2009 18:32
Yeah but you said if it's a 2d game, but the game is in 3d
silenus
15
Years of Service
User Offline
Joined: 4th Mar 2009
Location:
Posted: 9th Mar 2009 19:06
I said dbTAN, but Alex is right u need Tan-1
and thats it:

Quote: "dbATANFULL
This command will return the angle of two points in degrees between 0 and 360. The distance values are calculated by finding the distance between two points for both the X and Y axis.

Syntax
float dbATANFULL ( float fX, float fY )"


I think in my example you should use it this way:

dbATANFULL ( delta_x, delta_y ;

And I am not sure wether this works:


I would use something like this:
float target_angle;


And I think you need the angle around the Y axis, not dbObjectAngleZ(tank)
Further more, in your example it doesn't matter wether 2d or 3d, because your are just interessted in the angle around the Y-axis.

Login to post a reply

Server time is: 2024-09-30 19:26:07
Your offset time is: 2024-09-30 19:26:07