Bullet Force

For questions about using Classic.

Post » Fri Dec 24, 2010 3:25 pm

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?
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Fri Dec 24, 2010 7:26 pm

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.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sat Dec 25, 2010 10:28 am

[quote="newt":2ao98nc1]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.[/quote:2ao98nc1]

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.
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Sat Dec 25, 2010 11:19 am

Might try apply spring force, but it will only work on physics objects.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sat Dec 25, 2010 11:25 am

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???
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Sat Dec 25, 2010 5:41 pm

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:
[url:wq07fcc1]http://dl.dropbox.com/u/5426011/examples3/space.cap[/url:wq07fcc1]
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

Post » Sat Dec 25, 2010 9:13 pm

[quote="R0J0hound":23fxvqrw]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:
[url:23fxvqrw]http://dl.dropbox.com/u/5426011/examples3/space.cap[/url:23fxvqrw][/quote:23fxvqrw]

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.
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Sat Dec 25, 2010 11:46 pm

Yeah, that's the thing about physics, not only is it "doesn't play well with others", its also the bully on the playground.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests