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 / How do I animate a Tank?

Author
Message
Kedumba
14
Years of Service
User Offline
Joined: 21st Mar 2010
Location:
Posted: 25th Nov 2011 04:55
Hi All,
I'm really new to DarkGDK and I am still learning, so please forgive me if this is really simple.

I am writing a simple game in order to learn DarkGDK. I would like to have a "Tank" and drive it around my world and shoot the bad guys.

I have created a very simple 3d mesh of my tank which consists of 3 parts, the Tank body, the turret and the Gun. What I would like to know is how would I have the turret rotate and the gun raise and lower.

I'm planing to use keyboard controls to drive the tank and mouse to control the turret/gun so I'd like to have the 3 item moving independently.

I have already coded enough to get my tank moving around ,y landscape, I'm just not sure how to get the turret to rotate and the gun to raise/lower.

Thanks in advance
Hassan
14
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 25th Nov 2011 11:34 Edited at: 25th Nov 2011 11:42
a very simple way is this:
first off, you will need this setup:
-tank, turret and gun are exported as separate models

-turret is a cylinder-like shape (generally..), you will want to have the center of the circle (cross-section of the cylinder) at the center x/z in model space, y (height) of the turret is not important

-gun must be at the origin (x,y,z 0,0,0), i mean the beginning of it, and will probably be parallel to Z axis in model space

now for the code:
-have your turret to be positioned exactly at the same place as your tank (or if you have the turret y(height) centered, move it UP x units (x = turret height)(do that AFTER next step))

-have your turret rotated exactly like your tank, unless you want the turret rotating independantly(changes might occur to the next step)

-let YAW be the turret's angle, you will basically dbTurnObjectRight (or something..) on the turret and pass YAW as the angle (so that you can change it anytime)

-have your gun positioned exactly ontop of your turret, and if the turret was at the origin of the model space, move the gun UP x units (x is the y(height)(do that AFTER next step)

-have your gun rotated exactly like your turret

-now let PITCH be the angle of the gun, use dbPitchObjectUp (or something like that) on the gun and pass PITCH as the angle

-these steps are done every loop

a couple of notes:
-i forgot the function that could rotate an object to be at the same rotation as another, figure it out yourself, sorry.
-i'm not sure if a function to move UP exists, if not, you could do this:

-moving UP is not like positioning at (x, y+upOffset, z), because in this case, up will always be the world-space up, we want it relative to the current(tank's) angle
-if you want turrent rotation independant, guess it's tricky, it could work if you use YAW angle instead of the tank's y angle, but this could get buggy because of euler angle stuff, you will usually want the turret rotated with the tank as it rotates anyway

Kedumba
14
Years of Service
User Offline
Joined: 21st Mar 2010
Location:
Posted: 26th Nov 2011 08:53
Thanks for the reply.

So, to sum up, I need to export my "tank" and 3 separate models, then load them as three separate objects.

Position the 3 objects as individual items (Tank <x,y,z> Turret <x,y+5,z> etc then rotate and pivot as needed.

Ok, now I need to find 10 mins to play with this.. thanks again for the reply
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 26th Nov 2011 16:57
It may be easier if they are 3 separate limbs in the same model. Or fix them together as limbs after you load them.

This way they will all move relative to each other while giving you the freedom to also move them individually.

Login to post a reply

Server time is: 2024-03-28 13:51:45
Your offset time is: 2024-03-28 13:51:45