[ 9 posts ]  Reply to topicPost new topic 
Author Message
 [zz]
 Post subject: rotating sprite with horizontal movement?
PostPosted: Thu Dec 30, 2010 6:21 am 
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
Hey everyone, I need some help with this game i'm making .

So it's a game where you character is shooting up through the sky (vertically), and I need to,

1. when the character presses right, to go right AND for the sprite to rotate to the right as well. (same with left).
2. when the character is going right and releases the right key, to slow down and eventually stop (friction, I guess?) and rotate back to the left.
3. the character angle/direction should be equivalent with the amount of horizontal speed the character is going. (for example, if the character is barely moving to the right, the sprite should not be FULLY turned over at 90 degrees.)


I'm very sorry if I am asking for a lot, but I've been working with this game forever, and I just can't seem to get any of this working correctly. Any help will be greatly appreciated and you will be given credit.

 
Top
Offline 
 User page at mfgg.net
 
 [aq]
 Post subject: Re: rotating sprite with horizontal movement?
PostPosted: Thu Dec 30, 2010 1:22 pm 
User avatar
Obey.
Member
[*]
[*]
There's two things you can do to rotate:
-Make a rotate sprite or
-get GM Pro then use image_angle to rotate

For smooth motion step event:
Code:
//******************
//Keyboard checks
if keyboard_check(vk_right)
hspeed += anything

if keyboard_check(vk_left)
hspeed -= anything

//******************
//Friction (Used from my Mario)
hspeed = (abs(hspeed)-fric)*sign(hspeed) //One line!!!

//******************
//Max hspeed
if hspeed > maxspeed
hspeed = maxspeed

if hspeed < maxspeed*-1
hspeed = maxspeed*-1


But I don't know about the rotating. You have to put the origin of the sprite to the center.

_________________
I am your supreme leader
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: rotating sprite with horizontal movement?
PostPosted: Thu Dec 30, 2010 5:35 pm 
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
The game doesn't know what "fric" is. :(
Also, I assumed that I initialize the maxspeed varible in the create event to whatever I want it to be. This is correct, no?

 
Top
Offline 
 User page at mfgg.net
 
 [aq]
 Post subject: Re: rotating sprite with horizontal movement?
PostPosted: Thu Dec 30, 2010 11:00 pm 
User avatar
Obey.
Member
[*]
[*]
fric = friction but I think friction goes too fast for slowing down. It's a variablee that should be put in the create event.
You're right about the maxspeed, it's a variable.

Use this update:
Code:
//******************
//Keyboard checks
if keyboard_check(vk_right)
hspeed += anything

if keyboard_check(vk_left)
hspeed -= anything

//******************
//Friction (Used from my Mario)
hspeed = (abs(hspeed)-fric)*sign(hspeed)
if hspeed = 0
fric = anything
else
fric = 0

//******************
//Max hspeed
if hspeed > maxspeed
hspeed = maxspeed

if hspeed < maxspeed*-1
hspeed = maxspeed*-1

_________________
I am your supreme leader
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: rotating sprite with horizontal movement?
PostPosted: Fri Dec 31, 2010 12:43 am 
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
Now the character moves left and right without any acceleration/friction.

 
Top
Offline 
 User page at mfgg.net
 
 [aq]
 Post subject: Re: rotating sprite with horizontal movement?
PostPosted: Fri Dec 31, 2010 1:20 pm 
User avatar
Obey.
Member
[*]
[*]
How big are your variables? Try this then.

Code:
//******************
//Keyboard checks
if keyboard_check(vk_right) and !keyboard_check(vk_left)
{
hspeed += anything
movepress = 1
}
else if keyboard_check(vk_left) and !keyboard_check(vk_right)
{
hspeed += -anything
movepress = 1
} else movepress = 0

//******************
//Friction
if movepress = 0
friction = anything between 0 and 1
else
friction = 0

//******************
//Max hspeed
if hspeed > maxspeed
hspeed = maxspeed

if hspeed < maxspeed*-1
hspeed = maxspeed*-1

_________________
I am your supreme leader
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: rotating sprite with horizontal movement?
PostPosted: Fri Dec 31, 2010 3:59 pm 
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
Ugh... it still does the same thing.

So that code goes in the step event, right? and the only variables that go in the create event are maxspeed and movepress, right?

Also, I set maxspeed=5 and movepress=0
Is this right?

 
Top
Offline 
 User page at mfgg.net
 
 [aq]
 Post subject: Re: rotating sprite with horizontal movement?
PostPosted: Fri Dec 31, 2010 4:14 pm 
User avatar
Obey.
Member
[*]
[*]
It works fine. Did you change the frame rate to 60?

_________________
I am your supreme leader
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: rotating sprite with horizontal movement?
PostPosted: Fri Dec 31, 2010 5:58 pm 
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
If by that you mean room speed then yes

 
Top
Offline 
 User page at mfgg.net
 
« Previous topic | Next topic »
Display posts from previous:  Sort by  
 [ 9 posts ]  Reply to topicPost new topic 


Who is online

Users browsing this topic: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group