Public Group

#### Archived

This topic is now archived and is closed to further replies.

# What have I done wrong? VB+DX8

This topic is 5620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Alright, here we go! I have gotten my movement system down to the point I can move forwards, although it sometimes goes / or \ instead of | but I'm working on that. My real problem is that my backward and strafe movement seems to only stick to one axis, that being the X axis. Why won't it move along the z axis as well? Here is the code for this: ' Lets move forward If Keypressed = "DIK_W" Then ' Running forward(thus faster) camx = camx + (Sin(Angle) * 0.8) camz = camz + (Cos(Angle) * 0.8) Viewupdate = True End If ' Lets move back If Keypressed = "DIK_S" Then camx = camx + (Sin(Angle + g_180d) * 0.5) camz = camz + (Cos(Angle + g_180d) * 0.5) Viewupdate = True End If ' Lets rotate left If Keypressed = "DIK_LEFT" Then Angle = Angle + (g_90d / 18) If Angle < 0 Then Angle = g_360d - (-Angle) Viewupdate = True End If ' Lets rotate right If Keypressed = "DIK_RIGHT" Then Angle = Angle - (g_90d / 18) If Angle > g_360d Then Angle = 0 + (Angle - g_360d) Viewupdate = True End If ' Strafe left If Keypressed = "DIK_A" Then camx = camx - (Sin(Angle + g_270d) * 0.5) camz = camz - (Cos(Angle + g_270d) * 0.5) Viewupdate = True End If ' Strafe right If Keypressed = "DIK_D" Then camx = camx + (Sin(Angle + g_90d) * 0.5) camz = camz + (Cos(Angle + g_90d) * 0.5) Viewupdate = True End If ' Convert to correct angle system Angle = g_360d - Angle And then the update portion: ' // Update the view matrix with the new location and view 'make them identity matrices D3DXMatrixIdentity matView D3DXMatrixIdentity matPos D3DXMatrixIdentity matRotation D3DXMatrixIdentity matLook 'rotate around x and y, for angle and pitch D3DXMatrixRotationY matRotation, Angle D3DXMatrixRotationX matPitch, pitch 'multiply angle and pitch matrices together to create one 'look' matrix D3DXMatrixMultiply matLook, matRotation, matPitch 'put the position of the camera into the translation matrix, matPos D3DXMatrixTranslation matPos, -camx, -camy, -camz 'multiply that with the look matrix to make the complete view matrix D3DXMatrixMultiply matView, matPos, matLook 'which we can then set as the view matrix: D3DDevice.SetTransform D3DTS_VIEW, matView 'update details form Viewupdate = False All matrices are defined in this same sub, but they are never used outside of it, and it seems to update properly. When I add: Debug.Print Angle & ";" & camx & ";" & camy & ";" & camz & ";" & Keypressed I notice that the x axis is the only one changing on my A & D key presses, or my S keypress if I am facing along the x axis. If I am not facing along the x axis and press S, it doesn't move at all. So I believe it is a problem with my math, and not where I define the matrices or update the scene, but I can't say for sure after staring at this code for a week now. Anyways, help is greatly appreciated and thanks in advance. Edit: Forgot to mention that g_90d is 90 degrees in radians, same as g_180d is 180 degrees in radians, etc. [edited by - Revelations on June 3, 2003 2:41:26 AM]

##### Share on other sites
I''ve spent another day looking through this code and have determined that the problem is most likely in the fact that I never set Angleconv to the angle that the camera is actually looking. This then raised the question of how to determine the angle of the camera before moving it, so I could move it accordingly with my movement code, which seems to be sound. Now I feel really stupid for this, but how would I find the angle of the camera? Is there any way to make it tell me? Sorry for the newbie question...

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009712
• ### Who's Online (See full list)

There are no registered users currently online

×