Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / [2D]Sprite strafe according to sprite angle.

Author
Message
Ramon156
12
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 11th Dec 2012 12:52 Edited at: 11th Dec 2012 13:02
I'm kinda stuck on my player movement.
My player will be moving to and away from the mouse position by using W and S. When pressing A or D it should strafe according to the angle it's currently facing.




I've tried to :



This will update "NewAngle#" constantly. I'm not quite sure if I'm going in the right direction to create strafing. Should I save "Angle#" ONCE in a new variable, and strafe according to this new variable?
If so, how am I able to do this? Maybe a variable "Create_New_Angle" that changes between 1 and 0 to check if the "Angle#" has been stored once??

Thank you.


*Edit*
Here are the NewXValue2D and NewYValue2D functions:






And for anyone interested:

Make an array
Dim Keys(88,1)



Keys(X,0)
X = Keystate number
0 = press and hold
1 = press once
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Dec 2012 17:31
If your character is constantly facing the target, then you won't be strafing like you think. Instead it'll go in circles around the target. If you want to face the target but still strafe in different directions, you'd need to store two different angles; one to hold the direction it faces and the other for the direction in which it actually moves.

The simpler idea is to just not update the facing angle constantly, but perhaps only when moving toward or away from the object.

But to strafe left or right of your current angle, just add 90 degrees to your angle.




"You're not going crazy. You're going sane in a crazy world!" ~Tick
Ramon156
12
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 17th Dec 2012 10:31
Yes you're right, it's making me ill watching that! It works like I want it to work now, thank you Phaelex.

Login to post a reply

Server time is: 2024-04-24 06:15:10
Your offset time is: 2024-04-24 06:15:10