PDA

Click to See Complete Forum and Search --> : A Dilemma (kinda long)


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

plenderj
Mar 6th, 2001, 01:58 AM
Perhaps the player just goes sideways relative to the camera ?

HarryW
Mar 6th, 2001, 02:22 AM
I don't really see why you're using this code:
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


Looking at it after just quickly sketching it out on paper, I would use this code:
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


which I'm pretty sure is a perpendicular vector to the vector you were using. Try it, I have a feeling it will work.

Mar 6th, 2001, 01:49 PM
It seems there were two problems. Harry, you solved
one of them, Thanks =). The other problem is that I am
an idiot, and was using the formula to convert Radians
to Degrees, instead of Degrees to Radians.

Anyway, this is a pretty good example of VB Math.
What im doing is actually a C++ version of the code I
had written in VB. Harry, the problem you corrected, the
version I had worked in VB. For my problem, the VB
code I used to get the opposite angle was
360 - Rotation. This also worked.

Anyway, hopefully my idiocy will help someone in the future =). Good Luck!