Hiyas,
I have an angle between 0 and 359 (360 is 0). How do I get vectors from it?
Hope this is an easy enough question... =)
Thanks.
-Git
Printable View
Hiyas,
I have an angle between 0 and 359 (360 is 0). How do I get vectors from it?
Hope this is an easy enough question... =)
Thanks.
-Git
If a is 45, then:
That leaves a normalised vector, so you may need to scale it up.Code:u = ( cos 45 )
( sin 45 )
In VB:
Since VB uses Radians (like most computer languages), you'll need to use rad = deg * (pi / 180):Code:Dim a As Single
Dim x As Single
Dim y As Single
a = 1 ' Radians!!!!
x = Cos(a)
y = Sin(a)
Code:Function Deg2Rad(dDegrees As Double)
Deg2Rad = dDegrees * 0.0174532925199432957692369076848861
End Function
Hmm, I tried that, but it didn't really work.
What I'm trying to do is to make a movement engine similar to that in Grand Theft Auto - you use the left/right keys to rotate the person, and the up key to walk in that angle...
When I tried to implement your code, it was only in intervals of 45 degrees.
I don't really know trig too well, so I'd appreciate any help I can get. =)
-Git
Huh? It works fine for me, just use:Quote:
When I tried to implement your code, it was only in intervals of 45 degrees.
orCode:a = Deg2Rad(30)
...?Code:a = Deg2Rad(23.45235)
So, to walk one unit at an angle of 30 degrees, you'd do:
1. Convert angle to radians, and find (x,y) components
2. Move the person by each of those. If necessary, scale them up by the same amount
Ok, here's what I did.
Is that how to do it correctly? As I said, it appears to be moving in 45 degree intervals, still doing it... =(Code:If KeyCode = vbKeyUp Then
XVector = Cos(Rotation * 1.74532925199433E-02)
YVector = Sin(Rotation * 1.74532925199433E-02)
XOffSet = XOffSet + XVector
YOffSet = YOffSet + YVector
End If
-Git
This seemed to work for me:
Add a Shape to your form, and put it in the middle somewhere.Code:Dim rot As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyRight Then
rot = rot + 10
If rot > 360 Then rot = rot - 360
End If
If KeyCode = vbKeyLeft Then
rot = rot - 10
If rot < 0 Then rot = rot + 360
End If
If KeyCode = vbKeyUp Then
Shape1.Left = Shape1.Left + (Cos(rot * 1.74532925199433E-02) * 100)
Shape1.Top = Shape1.Top + (Sin(rot * 1.74532925199433E-02) * 100)
End If
Debug.Print rot
End Sub