Zaei
Mar 5th, 2001, 05:23 PM
I have a large Problem =(
I am trying to orient a Camera in 3D space so that it
follows the player (Third Person). The player has a
Rotation Value that determines which way it is facing,
and how to move it around. To do this, i have initialized
a lookup table with 360 sin and cos values. That looks
like this:
Const RAD = 180 / 3.14159
For i = 0 to 360
Theta = i * RAD
Array(i).X = Cos(Theta)
Array(i).Y = Sin(Theta)
Next i
For forward and backward movment:
If KeyUp Then
CurrPos.X = CurrPos.X + Array(Rotation).X
CurrPos.Z = CurrPos.Z - Array(Rotation).Y
End If
If KeyDown Then
CurrPos.X = CurrPos.X - Array(Rotation).X
CurrPos.Z = CurrPos.Z + Array(Rotation).Y
End If
For left and right, I just add or subtract 1 from the
Rotation value.
To Orient the camera, the code is:
X = Abs(Rotation - 180)
CameraPos.X = CurrPos.X - CamDistFromPlayer * Array(X)
CameraPos.Y = CurrPos.Y + 4
CameraPos.Z = CurrPos.Z - CamDistFromPlayer * Array(X)
If Ive done all of my math right, subtracting 180 from my
Rotation should give me the opposite angle. But, when I
run the code, when I push Up or Down, I go sideways.
Left and Right still rotate. Hopefully someone will come
up with the answer. Ive been working on this for about
5 days now =(
Thanks Much
I am trying to orient a Camera in 3D space so that it
follows the player (Third Person). The player has a
Rotation Value that determines which way it is facing,
and how to move it around. To do this, i have initialized
a lookup table with 360 sin and cos values. That looks
like this:
Const RAD = 180 / 3.14159
For i = 0 to 360
Theta = i * RAD
Array(i).X = Cos(Theta)
Array(i).Y = Sin(Theta)
Next i
For forward and backward movment:
If KeyUp Then
CurrPos.X = CurrPos.X + Array(Rotation).X
CurrPos.Z = CurrPos.Z - Array(Rotation).Y
End If
If KeyDown Then
CurrPos.X = CurrPos.X - Array(Rotation).X
CurrPos.Z = CurrPos.Z + Array(Rotation).Y
End If
For left and right, I just add or subtract 1 from the
Rotation value.
To Orient the camera, the code is:
X = Abs(Rotation - 180)
CameraPos.X = CurrPos.X - CamDistFromPlayer * Array(X)
CameraPos.Y = CurrPos.Y + 4
CameraPos.Z = CurrPos.Z - CamDistFromPlayer * Array(X)
If Ive done all of my math right, subtracting 180 from my
Rotation should give me the opposite angle. But, when I
run the code, when I push Up or Down, I go sideways.
Left and Right still rotate. Hopefully someone will come
up with the answer. Ive been working on this for about
5 days now =(
Thanks Much