Jump to content


Photo

Object (relative) movement speed


  • Please log in to reply
1 reply to this topic

#1 Tolemi959

Tolemi959

    GMC Member

  • New Member
  • 20 posts
  • Version:GM8

Posted 12 July 2012 - 09:31 AM

Ok, so I am working on a game (which is my first btw) and I am having trouble with the movement. This is the code I have so far:

if keyboard_check(ord("W"))
y -= 11
if keyboard_check(ord("S"))
y += 11
if keyboard_check(ord("A"))
x -= 11
if keyboard_check(ord("D"))
x += 11
if keyboard_check(vk_up)
y -= 11
if keyboard_check(vk_down)
y += 11
if keyboard_check(vk_left)
x -= 11
if keyboard_check(vk_right)
x += 11
image_angle = point_direction(x,y,mouse_x,mouse_y)

But I am having a few problems with it. The movement speed shouldn't add up when for example I press both ''W'' and ''Up'' at the same time. Also, what code do I have to use if I want to make some sort of speed vials? To temporary increase movement speed (say +3 relative movement speed for 150 steps). I suppose I would need to have a speed variable of some sort. Any help would be nice.
  • 0

#2 HerpDerp

HerpDerp

    GMC Member

  • New Member
  • 215 posts
  • Version:GM8

Posted 12 July 2012 - 11:13 AM

Ok, so I am working on a game (which is my first btw) and I am having trouble with the movement. This is the code I have so far:

if keyboard_check(ord("W"))
y -= 11
if keyboard_check(ord("S"))
y += 11
if keyboard_check(ord("A"))
x -= 11
if keyboard_check(ord("D"))
x += 11
if keyboard_check(vk_up)
y -= 11
if keyboard_check(vk_down)
y += 11
if keyboard_check(vk_left)
x -= 11
if keyboard_check(vk_right)
x += 11
image_angle = point_direction(x,y,mouse_x,mouse_y)

But I am having a few problems with it. The movement speed shouldn't add up when for example I press both ''W'' and ''Up'' at the same time. Also, what code do I have to use if I want to make some sort of speed vials? To temporary increase movement speed (say +3 relative movement speed for 150 steps). I suppose I would need to have a speed variable of some sort. Any help would be nice.


I'm not sure about the first problem with your movement, if you can explain it somewhat clearer I'll see if I can help.
For the "speed vial" thingy, what you want is basically some sort of power-up to give your char when he picks this up right?

For the speed vial: Create an object, obj_speedvial. Give it your powerup sprite etc etc.

Then:
CREATE-event for character:
movespeed=11 //the value for the normal movement code you have at the moment.
global.speedvial=0

STEP-event for character:
if global.speedvial=0
movespeed=11
if global.speedvial=1
movespeed=14 //I've added +3 reative speed to the standard movement speed. Experiment with this to your liking.

if keyboard_check(ord("W"))
y -= movespeed
if keyboard_check(ord("S"))
y += movespeed
if keyboard_check(ord("A"))
x -= movespeed
if keyboard_check(ord("D"))
x += movespeed
if keyboard_check(vk_up)
y -= movespeed
if keyboard_check(vk_down)
y += movespeed
if keyboard_check(vk_left)
x -= movespeed
if keyboard_check(vk_right)
x += movespeed
image_angle = point_direction(x,y,mouse_x,mouse_y)

COLLISION event for character colliding with obj_speedvial:
global.speedvial=1
alarm[0]=150    //put the number of steps for the powerup to last. I'll add 150 for the time being..
with other
instance_destroy() //destroys the speed vial again so you can only power up once per vial.

ALARM[0]-event for character:
global.speedvial=0  //The power-up has ran out of time and movement speed will be set back to normal.

That should do the trick.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users