Jump to content

Shooting To a Target


glass22
 Share

Recommended Posts

the correct way to do that such a thing is not by setting x & y each frame in order to keep the right path, what you need to do is to simply create a bullet, set the initial x & y (player position maybe) and set the direction and speed, and that's it, the bullet will automatically carry on to the correct path, if you are using Phaser then checkout these two examples (you better go through them in order just to understand the principle of shooting bullets in games) 

Link to comment
Share on other sites

You can give the bullet a movement vector that defines the amount it moves each update on the x & y axis.

for eg

function Bullet(){  this.position = {x:0,y:0}  this.velocity = {x:10,y:2}  this.update = function(){    this.position.x += this.velocity.x;    this.position.y += this.velocity.y;  }}

In your case you would want to adjust the velocity according to the distance between the bullets starting point and the co-ordinates of the user click so that it goes in the correct direction but maintains an appropriate overall speed.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...