Bullet behavior and Physics behavior

For questions about using Classic.

Post » Sat Dec 11, 2010 10:19 pm

I'm making a Space War type game and having a little problem with Bullet Physics.

I want the bullets in the game to have force applied towards a center Black Hole object... I have a player ship with this behavior working perfectly using Physics Behavior (thanks Davioware!). But when I made a bullet and added both Bullet and Physics behavior to it in an attempt to do the same thing, everything went terribly wrong.

So, I'm assuming that Bullet Behavior and Physics Behavior don't play nice together? If that is the case, what is the most efficient way to manually create bullet movement? Is there an example/faq/tutorial for this that anyone can point me at?

Thanks!
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Sat Dec 11, 2010 11:09 pm

Why do you want your bullets to use physics behavior specifically? Will they need to collide and bounce around physically? If not then physics behavior shouldn't be used. The only time you should use it is if you want physics based interaction between objects. Using it solely for the purpose of vector based movement/inertia is inefficient; for that you should use custom movement behavior. In general you shouldn't combine two movement behaviors unless you're manually toggling between them for a certain reason. Physics behavior hijacks the x,y, and angle of an object, so adding a bullet behavior on top will just apply angle based movement to the object after its movement has already been physically solved and applied by physics behavior. Bullet behavior is dead simple, and is equivalent to the "move at angle" action, minus the time-delta adjustment.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Sat Dec 11, 2010 11:21 pm

It's not that hard to do physics based bullets. Do you want something like this?
http://dl.dropbox.com/u/10316081/phymachgun.cap
B
51
S
10
G
7
Posts: 184
Reputation: 6,825

Post » Sat Dec 11, 2010 11:24 pm

[quote="Davioware":1hy8dfe7]Why do you want your bullets to use physics behavior specifically? Will they need to collide and bounce around physically? If not then physics behavior shouldn't be used. The only time you should use it is if you want physics based interaction between objects. Using it solely for the purpose of vector based movement/inertia is inefficient; for that you should use custom movement behavior. In general you shouldn't combine two movement behaviors unless you're manually toggling between them for a certain reason. Physics behavior hijacks the x,y, and angle of an object, so adding a bullet behavior on top will just apply angle based movement to the object after its movement has already been physically solved and applied by physics behavior. Bullet behavior is dead simple, and is equivalent to the "move at angle" action, minus the time-delta adjustment.[/quote:1hy8dfe7]

The Physics behavior is how I modeled the Black Hole. By using the "Add Force Towards" action.

I was just trying to achieve the same effect with the bullets... If you shoot them past the black hole, they CURVE towards it, and/or get sucked in entirely. That way, during the game, you can do "Trick shots" where you aim near the Black Hole and the shot will angle around it and make a complete left turn (or whatever.)

So, is there a manual way to do "add force towards" using Bullet or Custom movement Behaviors?

I'll attach the file I'm working on (minus bullets) so you can see the "add force towards" effects.

[url:1hy8dfe7]http://www.mediafire.com/file/jjr27flssssxluo/How%20to%20Add%20Bullet.cap[/url:1hy8dfe7]
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Sat Dec 11, 2010 11:29 pm

[quote="Yarfapet":3juaxw2x]It's not that hard to do physics based bullets. Do you want something like this?
http://dl.dropbox.com/u/10316081/phymachgun.cap[/quote:3juaxw2x]

Got it. I'll try it this way. Thanks!
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Sun Dec 12, 2010 12:09 am

use custom movement and "set speed toward position", and choose accelerate as the type. It functions the exact same way as physics. Like I said, if you want vector based movement (ie. Inertia physics, without the collisions) then use custom movement.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Sun Dec 12, 2010 12:37 am

[quote="Davioware":2rz4xkp3]use custom movement and "set speed toward position", and choose accelerate as the type. It functions the exact same way as physics. Like I said, if you want vector based movement (ie. Inertia physics, without the collisions) then use custom movement.[/quote:2rz4xkp3]

Got it... I now have it working with both Physics and Custom movement. They're more or less identical (still playing with the math.)

Is custom movement more efficient in terms of processor overhead? Is that what makes it a better choice than Physics? Just curious.

Thanks again!
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Sun Dec 12, 2010 12:53 am

One last question (I hope :? ): Now that I'm no longer using the bullet behavior, what is the best way to set a range for the bullets? My guess would be some version of destroying it over TimeDelta? Also, should I be using TimeDelta to regulate the bullet speed (so it will run the same on different computers)?
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Sun Dec 12, 2010 1:09 am

[quote="BluepointVance":fwve06zr]Is custom movement more efficient in terms of processor overhead? Is that what makes it a better choice than Physics? Just curious.[/quote:fwve06zr]
Yes.

[quote="BluepointVance":fwve06zr]One last question (I hope :? ): Now that I'm no longer using the bullet behavior, what is the best way to set a range for the bullets? My guess would be some version of destroying it over TimeDelta? Also, should I be using TimeDelta to regulate the bullet speed (so it will run the same on different computers)?[/quote:fwve06zr]

Using timedelta in your movement calculations makes the game run at the same relative speed regardless of the frame rate. For example, when the frame rate drops due to lag, objects will perform large steps of movement, which may result in missed collision or other unwanted things. You can also set a special setting for timedelta which remedies the aforementioned problem; it modifies the timedelta if the value gets to low, so that the game goes from "skip frame" lag, to "slowdown lag" if passes a certain threshold. Timedelta is not mandatory however. You can use a fixed frame rate for when you want to program to run with frame based logic, instead of time based logic. Without timedelta however, if you select V-synced framerate, then your game will run at different speeds depending on the monitor's refresh rate. If you need pixel perfect collisions, reliability and consistancy (ie. low res platformer), then use a fixed frame rate. If you want to be able to slowdown time in your game, then you need to incorporate timedelta (there are ways around that but I won't get into that).
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests