Stop bullet when it reaches touched location

1 favourites
  • 10 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • Hello,

    Currently the player can fly around the screen with touch. You tap anywhere on the screen, and the Player (bullet) moves to the location (on tap: set bullet speed to 100). On the tap gesture I store Touch.X and Touch.Y in global variables called 'TouchX' and 'TouchY'.

    Then, every tick the Player rotates toward 'TouchX' and 'TouchY'.

    Now, this works, but when the Player is at the location it starts spinning around its self. What I prefer it to do is, 50 pixels before the touched location the Player to gradually slow down to 0 bullet speed, and just stand still on the screen.

    I looked at some samples where you store the Player initial location into variables, and compare it with distance. But I was unable to translate it into my example.

    Any ideas?

    Regards

  • There is an example for you :

    Bullet Control

    Example :

    drive.google.com/open

  • I suggest doing this with MoveTo addon. Bullet is more suited for "shoot and forget" tasks. When you need to move object from one point to another predictably, with acceleration/deceleration, MoveTo is a much better choice.

  • Hi,

    Maverick1912 Thanks for your effort, I tried your example and also integrated it in my own file, but the sprite doesn't seem to slow down to zero or does it just appear that way (because of the 50 px distance)?

    Also the sprite moves to a different location when you click on the exact spot the sprite stopped.

    Could you tell me how you got to Player.Width+2? And Self.Bullet.Speed-50?

    So first calculate the distance between the touched location and the sprite, and when the distance is smaller or equal to the Player's width +2 (what does '2' add?) the bullet speed of the sprite is set to -50 speed.

    I'm just trying to grasp what happens and the logic behind it.

    Edit: In your example the bullet also stops not precisely at the clicked location. I noticed this in my own file, where my sprite stopped about 30 pixels before the exact touched location.

    dop2000 Hey I prefer to stay away from plugins. I really, really want to try to do this with 'vanilla' Construct 2, as plugins may cause issues and is probably why they're 3rd party in the first place?

    Perhaps you have some idea..

    Regards

  • ah it is not +, it is divide symbol, so when the distance < the sprite.width/2, it will start decreasing the speed.

    When it's speed less than 0, it will disable the bullet.

    I have put my example in my previous reply, but maybe you didn't noticed that. Here is the link :

    drive.google.com/open

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi,

    Thanks. I just noticed in Construct 3, the divide symbol is indeed different, but looks like a '+'.

    I tested your link, and it works. Just that the sprite doesn't stop exactly at the touched location. In my file for example, the player sprite stops about 40 pixels before the exact touched place (measured from the image point of the sprite to touch x and y).

    Thanks.

  • Is the deceleration you trying to do when the distance is less Than 50 is because you trying to stop the object? or because you trying to that effect?

    I wouldn't use the bullet either for this situation as Dop2000 said the bullet is more as a constant movement you need some behaviour that has more supports for deceleration

    Have you tried the (move at Angle)

    https://www.dropbox.com/s/13hebrbvquv6oo5/StopBulletOnDestination.capx?dl=0

    if you really need the deceleration when the distance is 50 or less just add another condition (Dist <= 50) and do the deceleration on there

    And here you don't really need the rotation like the bullet you can just set the Angle, you can remove the rotation if you like

  • Hi,

    Thanks. I just noticed in Construct 3, the divide symbol is indeed different, but looks like a '+'.

    I tested your link, and it works. Just that the sprite doesn't stop exactly at the touched location. In my file for example, the player sprite stops about 40 pixels before the exact touched place (measured from the image point of the sprite to touch x and y).

    Thanks.

    I made example that the distance is < than your sprite width/2.

    Of course you can change my condition to make it fits with your requirements.

  • maybe this has been solved already, but since you wanted to keep it vanilla here is my approach, should apply to your bullet behavior also ... they are working on same principles.

    is going to be a pain in the "bowl" to make that bullet bounce of objects though.

  • delete comment

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)