VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Better Movement Tutorial

by Dude2 (1 Submission)
Category: Games
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

Teaches about using trig to move objects better and more realistically

Rate Better Movement Tutorial

Hey everyone! Have you ever wondered fow to get your objects to move everywhere (instead of up, down, left and right)? If so, read on!
In math, there are two functions calles Sine and Cosine. I could get into all the details on how they work, but i'm pretty sure you'll get bored. Anyway, you use them in vb as Sin(x) and Cos(x) with x being a number. To implement it in a moving sub would be like:
Sub moveit(angle as double)
x = x + sin(angle)
y = y + cos(angle)
End Sub
Go ahead, try it! You find that if you put in a degree (like 90, which should make it go to thr right), it WILL NOT WORK. That is because you need to get radians and multiply them by the degrees. That is where mist newbies screw up. To get the amount of one radian, you do this:
Const Pi = 3.14
Const Rad = 3.14 / 180
Then, we make a little change to the procedure:
Sub moveit(angle as integer)
x = x + sin(angle * rad)
y = y + cos(angle * rad)
end sub
and that is basically it.
C U Later!
Dude2
PS> Please vote for me if you think it is good/helpful!

Download this snippet    Add to My Saved Code

Better Movement Tutorial Comments

No comments have been posted about Better Movement Tutorial. Why not be the first to post a comment about Better Movement Tutorial.

Post your comment

Subject:
Message:
0/1000 characters