glass22 Posted December 18, 2013 Share Posted December 18, 2013 Hi, I'm looking to shoot a bullet when I click the mouse, I know how to make it go towards the mouse click, but how can I make it carry on past it? is there anyway to set a localX and localY? Quote Link to comment Share on other sites More sharing options...
aladine Posted December 19, 2013 Share Posted December 19, 2013 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) Invaders exampleTank example Quote Link to comment Share on other sites More sharing options...
alex_h Posted December 19, 2013 Share Posted December 19, 2013 You can give the bullet a movement vector that defines the amount it moves each update on the x & y axis.for egfunction 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. Quote Link to comment Share on other sites More sharing options...
glass22 Posted December 19, 2013 Author Share Posted December 19, 2013 Thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.