Results 1 to 4 of 4

Thread: A Dilemma (kinda long)

  1. #1
    Zaei
    Guest
    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:
    Code:
    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:
    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
    For left and right, I just add or subtract 1 from the
    Rotation value.

    To Orient the camera, the code is:
    Code:
    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

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Perhaps the player just goes sideways relative to the camera ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I don't really see why you're using this code:
    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:
    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.
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    Guest
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width