I would like to be able to move my player, or whatever it may be, in a specific degree.
As for now, I have to make a single function for each degree (usually only up, down, left, right).
But I want a function like "void moveDeg(int degree, int distance)".
How would I make this function?
And also, I am working on a game that features joysticks. Here I get the the X position and the Y position of the analog stick (one of them).
How could I convert those numbers to a degree?
Even though this may only be a math question, I'll let you know that I'm using C++.
I would be grateful for any links and posts. Thanks!
Make something move in a specific degree
Moderator: Coders of Rage
- superLED
- Chaos Rift Junior
- Posts: 303
- Joined: Sun Nov 21, 2010 10:56 am
- Current Project: Engine
- Favorite Gaming Platforms: N64
- Programming Language of Choice: C++, PHP
- Location: Norway
Make something move in a specific degree
Last edited by superLED on Thu Sep 22, 2011 9:30 am, edited 1 time in total.
Re: Make something move in a specific degree
sounds like vector based movement
Re: Make something move in a specific degree
Do you really need angles for this?
Just check the X/Y values of the joystick.
For example:
I have no idea exactly what libraries/framework you're using or even what input device you're trying to use. But I find it hard to believe you can only get the angle of the analog stick....
Just check the X/Y values of the joystick.
For example:
Code: Select all
if ( JoyX < 0 )
{
PosX -= movementVal;
}
else if ( JoyX > 0 )
{
PosX += movementVal;
if ( JoyY < 0 )
{
PosY -= movementVal;
}
else if ( JoyY > 0 )
{
PosY+= movementVal;
}
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: Make something move in a specific degree
Vector addition!
If you need further explanation, just ask. You just need to understand a little about vectors.
Hmm my edit seems to have disappeared...
Take a look at this video on vectors, I know you've seen it!!
http://www.youtube.com/watch?v=sDDRZv5QM80
If you need further explanation, just ask. You just need to understand a little about vectors.
Hmm my edit seems to have disappeared...
Take a look at this video on vectors, I know you've seen it!!
http://www.youtube.com/watch?v=sDDRZv5QM80
Last edited by short on Thu Sep 22, 2011 11:48 am, edited 2 times in total.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Make something move in a specific degree
I'm fairly certain you are misusing the term "degree" here. I was thinking you wanted some sort of rotational mathematics, but what you're asking for does sound like simple vector addition...
- superLED
- Chaos Rift Junior
- Posts: 303
- Joined: Sun Nov 21, 2010 10:56 am
- Current Project: Engine
- Favorite Gaming Platforms: N64
- Programming Language of Choice: C++, PHP
- Location: Norway
Re: Make something move in a specific degree
I am sing SDL. I am getting the X and Y position of the axis. Something between +3600 to -3600 on each axis.N64vSNES wrote:Do you really need angles for this?
Just check the X/Y values of the joystick.
For example:
I have no idea exactly what libraries/framework you're using or even what input device you're trying to use. But I find it hard to believe you can only get the angle of the analog stick....Code: Select all
*code*
If I used this code, wouldn't the object move pretty fast if the axis is all the way to 3600?
Thanks for that beauiful paper! I will look into that and see what I can get out of it ^^short wrote:Vector addition!
*image*
If you need further explanation, just ask. You just need to understand a little about vectors.
Hmm my edit seems to have disappeared...
Take a look at this video on vectors, I know you've seen it!!
http://www.youtube.com/watch?v=sDDRZv5QM80
Yes. I think I really ment angle. But that may be a invalid term as well, given that I don't have english as my mother thounge, and I am not that talented with math. But I hope the point of the question was clear anyway.GyroVorbis wrote:I'm fairly certain you are misusing the term "degree" here. I was thinking you wanted some sort of rotational mathematics, but what you're asking for does sound like simple vector addition...
I will look around for vector addition, and see what I can find. Thanks!
Re: Make something move in a specific degree
you could always calculate this a percentage, and then multiply that by the amount of movement you actually want..superLED wrote: I am sing SDL. I am getting the X and Y position of the axis. Something between +3600 to -3600 on each axis.
If I used this code, wouldn't the object move pretty fast if the axis is all the way to 3600?