GameMaker: Studio

GameMaker: Studio

View Stats:
TurtleYawns 18 Mar, 2016 @ 3:50pm
Moving in direction of Sprite
I am having trouble trying to get the movement of a 2D 'space ship' that rotates 360 degrees to work. I tried setting the code on the Key press to: [ Speed=4 ]. But that doesn't seem to work, I must be doing something stupid because I swear this normally works. The way I am making the sprite rotate is using the following code: [ image_angle -= 5 ] or [ image_angle += 5 ].

If anyone could help me with this I'd be very grateful as I could finally start on everything else aha. I will eventually be changing the speed to become a relative to +0.1 every time the 'W' key is pressed. This is meant to simulate more of an accelerator and the 'S' key will do the opposite (-0.1) every time it's pressed. This will cause it to be more fluid in the game and also make it harder to avoid fast approaching objects if the player is travelling too fast.
< >
Showing 1-8 of 8 comments
Beamy 18 Mar, 2016 @ 4:01pm 
Instead of changing the image_angle directly, change the variable "direction"
Then, in the end step event, type in the following code:

image_angle = direction;

Changing the image_angle only changes the way the sprite faces, not the direction the object will move.
TurtleYawns 19 Mar, 2016 @ 1:32pm 
Originally posted by BeamKirby:
Instead of changing the image_angle directly, change the variable "direction"
Then, in the end step event, type in the following code:

image_angle = direction;

Changing the image_angle only changes the way the sprite faces, not the direction the object will move.

That worked with all my other problems but the event: Key press UP: Speed=4
doesn't work still :S But what you said fixed my firing lazer problem :D
TurtleYawns 20 Mar, 2016 @ 7:27pm 
[BUMP] Still cannot get the code:
[ Speed=4 ]
to work. All the rotation is working great and all based on the direction of the object not the sprite. but I cant get the object to move in the direction its facing.
Are you using physics or no?

If you are using I believe, could be wrong, that "speed" won't work and you'll need to use the physics "impulse" or "force" or to push / propel your ship.
Last edited by BOYCOTT S-T-E-A-M!; 20 Mar, 2016 @ 9:54pm
sitebender 20 Mar, 2016 @ 9:30pm 
do you have ord("W") or ord("w") One will work and the other will not.

Capitals and lower cases matter.
Last edited by sitebender; 21 Mar, 2016 @ 6:46am
TurtleYawns 21 Mar, 2016 @ 12:27am 
Originally posted by BOYCOTT S-T-E-A-M!:
Are you using physics or no?

If you are using I believe, could be wrong, that "speed" won't work and you'll need to use the physics "impulse" or "force" or to push / propel your ship.

I'm guessing I'm not using physics as I don't know how to turn it on. You see it works with the ship's bullet it fires, I set its direction up when its created and then set its speed in the end step and it works fine, but not the ship itself.



Originally posted by sitebender:
do you have ord("W") or ord("w") One will work and the other will not.

I'm currently using the drag and drop action of Key Pressed [ UP ] - to activate the speed change
TurtleYawns 21 Mar, 2016 @ 12:35am 
Ignore me guys, thank you the problem was I was using a capital S on speed. so instead of speed=4 I was using Speed=4 which it didnt recognise, awesome thanks you all as you giving me feedback made me look over again in more detail what I had done :)
var right_move = (keyboard_check (vk_right) or keyboard_check (ord("D")))
var left_move = (keyboard_check (vk_left) or keyboard_check (ord("A")))
var up_move = (keyboard_check (vk_up) or keyboard_check (ord("W")))
var down_move = (keyboard_check (vk_down) or keyboard_check (ord("S")))



if right_move {
phy_position_x += 5
sprite_index = right_move_anim
}
if up_move {
phy_position_y -= 5
sprite_index = jump
}
if left_move {
phy_position_x -= 5
sprite_index = left_move_anim
}
if down_move {
phy_position_y +=5
sprite_index = sit
}
if (!right_move and !left_move and !up_move and !down_move){
sprite_index = Sprite5
}
вставь нужные названия спрайтов и всё будет хорошо работать, прописывать нужно в скрипте Step (Rus)
< >
Showing 1-8 of 8 comments
Per page: 1530 50