arrow glitches help

P

piksil_demon

Guest
ok so heres what im aiming for.
1 i want my character to move in 8 directions, but attack in 4.
2 i want the direction he attacks in to be the direction of the last key he pressed.
with that said here is the problems i have with my current code.
1. it shoots in the diagonal directions. i want it to only shoot the up, down, left, and right
2. it shoots multiple at once
3. when i hole up and down together, or left and right together then shoot, the bullet always shoots to the right.
here is the code for my arrow and player
Code:
[B]Information about object: obj_player[/B]
Sprite: spr_player
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

MaxHp= 10
Hp = 10

Hspd= 0
Vspd= 0

Spd=5
SpdX = 1
Dblspd=false

Attack=1
DblAttk=false

Def=1
DblDef=false

Arrows=20
InfArrow = false
Inv=false

alarm[0]=0

Step Event:
execute code:

up = keyboard_check(ord('W'))
down = keyboard_check(ord('S'))
left = keyboard_check(ord('A'))
right = keyboard_check(ord('D'))
ranged = keyboard_check(vk_space)


//not moving/ pressing opposite keys
if!left & !right & !up &! down or up & down or left & right
{Spd=0}
else{Spd = 5*SpdX}

//movemnt code
var Hspd= (right - left)
var Vspd= (down - up);

//diagonal speed equlalizer
var d = point_direction(0, 0, Hspd, Vspd);
x += lengthdir_x(Spd, d);
y += lengthdir_y(Spd, d);


if (ranged) {
   with (instance_create(x, y, obj_bullet)) {
       direction = d;
       speed = 11;
   }
}
Code:
[B]Information about object: obj_bullet[/B]
Sprite: spr_bullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

BulletSpd=11

Step Event:
execute code:


Collision Event with object obj_wall:
execute code:

instance_destroy()
 
Last edited by a moderator:

NicoFIDI

Member
On create
Code:
/// Initialize obj
shoot_direction = 0;
On keep pressed up
Code:
/// set shoot_direction  to up
shoot_direction = 90;
On keep pressed left
Code:
/// set shoot_direction  to left
shoot_direction = 180;
On keep pressed down
Code:
/// set shoot_direction  to down
shoot_direction = 270;
On keep pressed right
Code:
/// set shoot_direction  to right
shoot_direction = 0;
On start to press shoot
Code:
/// Shoot that thing!!
var to_the_infinite_and_beyond = 15;
var bullet = instance_create(x,y,obj_bullet);
bullet.speed = to_the_infinite_and_beyond;
bullet.direction = shoot_direction;

Disclamer: up and down might be the oposite degree :p
 
P

piksil_demon

Guest
On create
Code:
/// Initialize obj
shoot_direction = 0;
On keep pressed up
Code:
/// set shoot_direction  to up
shoot_direction = 90;
On keep pressed left
Code:
/// set shoot_direction  to left
shoot_direction = 180;
On keep pressed down
Code:
/// set shoot_direction  to down
shoot_direction = 270;
On keep pressed right
Code:
/// set shoot_direction  to right
shoot_direction = 0;
On start to press shoot
Code:
/// Shoot that thing!!
var to_the_infinite_and_beyond = 15;
var bullet = instance_create(x,y,obj_bullet);
bullet.speed = to_the_infinite_and_beyond;
bullet.direction = shoot_direction;

Disclamer: up and down might be the oposite degree :p
please specify if this is intended to be in the player code, or arrow code
 

NicoFIDI

Member
It should be in the player,
on the event spesified.

PD: maybe you wanna change the name of variables and objects to the right ones,
except the infinite and beyond variable of course, that's the crutial part in all the code.
 
P

piksil_demon

Guest
It should be in the player,
on the event spesified.

PD: maybe you wanna change the name of variables and objects to the right ones,
except the infinite and beyond variable of course, that's the crutial part in all the code.
i fail to see where, or how the "infinite and beyond" fits into the code
 

NicoFIDI

Member
Mhmmm...
Then i cant help you.
That's something that every developer struggles.
Maybe some day you find how "infinite and beyond" it's the base for all.

PD: it's a joke, that's a weird name for the bullet_speed.
PD2: if it helps just let me know :)
 
Top