Jump to content


Photo

3D projectiles moving on z-axis


  • Please log in to reply
5 replies to this topic

#1 Pharrahnox

Pharrahnox

    GMC Member

  • GMC Member
  • 528 posts
  • Version:GM7

Posted 06 July 2012 - 01:45 AM

I have started making a 3D shooting game, where you can fly, and I would like the bullets to go exactly where you are aiming. At the moment the bullets lose accuracy as your zdirection gets further from 0. When closer to 0, the bullets will hit very close to where you are aiming, but when you aim up, they are way off the mark...

I have thought about using a ratio or something, such as a speed/zspeed ratio, where it would take into account the zdirection / 90 or something like that.

The method atthe moment is just:

z += zdirection / speed;

Where:

z = obj_player.z;
zdirection = obj_player.zdirection;
speed = 60;

I want it so that it only travels at a speed of 60, not in just on the xy-plane, but up as well. I have tried various different methods I have found on the internet, but they all have the same problem.

Any help would be much appreciated.
  • 0

#2 LowchefBox

LowchefBox

    GMC Member

  • GMC Member
  • 20 posts
  • Version:GM:HTML5

Posted 06 July 2012 - 02:36 AM

z+=lengthdir_y(speed,zdirection)
  • 0

#3 Pharrahnox

Pharrahnox

    GMC Member

  • GMC Member
  • 528 posts
  • Version:GM7

Posted 06 July 2012 - 03:16 AM

z+=lengthdir_y(speed,zdirection)


It has the same problem. There must be somethign wrong with the zdirection variable.

I change it from
zdirection = obj_player.zdirection
to
zdirection=(display_mouse_get_y()-display_get_height()/2)/10*(obj_player.side_speed/100);
but it didn't make a difference. Can you see where I'm going wrong? I have a crosshair displayed in the centre of the view, and that is how I can easily tell the zdirection is off. obj_player.side_speed = 35;

Edited by Pharrahnox, 06 July 2012 - 03:17 AM.

  • 0

#4 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14384 posts
  • Version:GM:Studio

Posted 06 July 2012 - 04:14 AM

Did you forget to adjust the hspeed and vspeed to take into account the fact the bullet is going up?

Tentatively this should do it...
setup bullet
direction = ???
zdirection = ????
speed = 10;
zspeed = lengthdir_y(speed,zdirection)
speed = lengthdir_x(speed,zdirection)


bullet end step
z+=zspeed;
  • 0

#5 Pharrahnox

Pharrahnox

    GMC Member

  • GMC Member
  • 528 posts
  • Version:GM7

Posted 06 July 2012 - 08:13 AM

I've tried that method before and it had the same problem. But now when I tried it, the bullet didn't go up at all. I don't know what I have done wrong. In the create event I have:
direction=obj_player.direction; 
zdirection=(display_mouse_get_y()-display_get_height()/2)/10*(obj_player.side_speed/100);

zspeed = lengthdir_y(speed,zdirection); 
speed = lengthdir_x(speed,zdirection); 
and in the Step Event I have:
z+=zspeed;

  • 0

#6 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14384 posts
  • Version:GM:Studio

Posted 06 July 2012 - 06:45 PM

you simply forgot
speed = 10;

before the lengthdir lines
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users