Bullet Force

This forum is currently in read-only mode.
From the Asset Store
Build a thrilling space station scenario with these level assets and characters.
  • In the Space Wars-type game I'm doing, I want to make it so when a bullet collides with a ship, it imparts some amount of force -- i.e. the ship gets knocked back a little.

    The ships are set up with the physics behavior, so I figured I could just use the ADD FORCE TOWARDS action -- with the angle being the angle of the bullet... Unfortunately when I try this, it seems to do nothing at all... I think *maybe* because the bullet is destroyed immediately afterwards..?

    Is there a smarter way to be doing this? I'm I approaching it incorrectly?

    I kept thinking maybe I should be storing the bullet trajectory in a variable and using that -- not that I'd actually know how to do that... It just sounded good in my head.

    Any advice?

  • Again this would easily be solved by the custom movement behavior, bullet on collision with ship, ship bounce.

    Also I don't think the bullets destruction is the problem. The bullet's information is still available, as long as its within the same event.

    If this is just for effect, I would suggest a camera shake. Linkmans camera plug does this quite well.

  • Again this would easily be solved by the custom movement behavior, bullet on collision with ship, ship bounce.

    Also I don't think the bullets destruction is the problem. The bullet's information is still available, as long as its within the same event.

    If this is just for effect, I would suggest a camera shake. Linkmans camera plug does this quite well.

    Tried custom movement and bounce... Ship wouldn't move. Possibly because I have physics on the ship? Tried set force towards and add force towards -- also does absolutely nothing... I'm totally confused... Any other ideas?

    Also this isn't really for effect, it's an actual gameplay mechanic that you get knocked back or to the side when your ship is shot.

    The only thing I can think is to add the physics behavior to all the bullets -- and then give them a large mass. I guess I'll try that out, unless anyone has a better suggestion.

  • Might try apply spring force, but it will only work on physics objects.

  • I solved part of it... The problem was the amount of force being applied.

    When I set it to a normal amount of force (250-400, about the same amount the ship gets when you're thrusting) the ship refused to move. But if I upped that amount to say, 100,000 -- suddenly the ship moved just a little bit as desired.

    I think this might have to do with the amount of time before the bullet is destroyed (a tick, two?) -- Because when I removed the bullet destroy action and just let the bullet fly right through the player's ship, suddenly the ship would move -- even at low force values of 200 or so... I *think* because the bullet and ship are interacting for more ticks in that scenario. (This is all just my guess, what the hell do I know??)

    Anyway, the code to move the ship now looks like this:

    Ship1: Add force 100,000 towards (Ship1.X + cos(Bullet.Angle), Ship1.Y + sin(Bullet.Angle))

    Seems to work anyway...

    But I also need to apply some amount of torque to the ship so it's angle is changed as well as it's force... The net result of these two lines of code should be a physics version of the "bounce" action from custom movement.

    Unfortunately, I can't figure out how to calculate the angle of the bullet vs the angle of the ship to make that torque direction look believable.

    Is there a way to do that?? I'm guessing by using math which I suck at?? Thoughts???

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No need to calculate the angle. Just give the bullets the physics behavior and the kickback from the bullets hitting the player will be handled automatically.

    Here's an example of what I'm suggesting:

    http://dl.dropbox.com/u/5426011/examples3/space.cap

  • No need to calculate the angle. Just give the bullets the physics behavior and the kickback from the bullets hitting the player will be handled automatically.

    Here's an example of what I'm suggesting:

    http://dl.dropbox.com/u/5426011/examples3/space.cap

    Strange... In that space.cap -- When I just run it, there is no kickback at all. But if I change the red ship's collision mask from "custom" to "bounding box" it works perfectly. I've got no idea why... I'm running Construct 0.99.96. Weird.

    Anyway, I think this "physics bullet" route is the one to take. Thanks R0J0hound and Newt! Gotta go be sociable for Christmas now. Damn.

  • Yeah, that's the thing about physics, not only is it "doesn't play well with others", its also the bully on the playground.

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