Entity LifeSpan

Discuss any questions about BEPUphysics or problems encountered.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Entity LifeSpan

Post by Rompetoto »

Okay so i want to create a "tower" that shoots spheres and i want the sphere to bounce around for a while, but when they are at rest(linearVelocity == Vector3.Zero), then i want them to disappear. I have sorta got it working, but it seems that the Game components are not being updated correctly. I have thought about making my own entity like Projectile that might have a life span attribute that could help solve this problem. What are your thoughts on this?

Thanks, Richard.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

I usually suggest not creating custom BEPUphysics.Entity types, mostly out of preference. Instead, I suggest doing something like it sounds like you are already doing, which is have a 'game logic' object which has as a field within it the entity. That logic object would keep track of the time since entity creation and would then tell the space to remove the entity when it becomes sufficiently old.

Using a separate game logic object as opposed to an extension of the physics entity feels more natural to me primarily because game objects are usually considered to 'own' physical properties, but the game objects are not themselves physical properties. Also, game objects commonly have their own chain of inheritance.

The game logic object could be a GameComponent object or just an object that is updated manually from the game's update method. GameComponents should be able to do what you need; in what way did they appear to be failing?

By the way, the deactivation system maintains an activity state that you can check instead of the velocities. It's the entity.isActive property. If it's false, then the entity is asleep.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Ok the game object thing sounds good, thats pretty much what im doing. But the problem comes in when i am removing the object. Like i said, it works fine when i remove it from the space, but not from the actual game components(basically its not showing that the ball is gone....)

And thanks for the asleep attribute, does that automatically turn on when the object is stopped?

Richard
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

Yes, when it stops moving (within some limit), an entity goes to sleep and the entity.isActive flag becomes false. Anything interacting with the object will wake it back up.

Are you using a DrawableGameComponent and just calling Components.Remove when it's supposed to be gone? If you're calling either the component's Update or Draw methods manually, keep in mind that the Game will also call them (if you add them to the game's Components list). If you want to re-use the GameComponent, there is a Visible property that can be set while the instance is unused.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Ok, i figured out how to make the game components and the update stuff, but now when i try to remove the spheres from the world, all the spheres in the world get removed...

Also, on a side note, what would be a good way to shoot a sphere from a "tower"(a box in the space) to another target using a specific velocity.

Thanks for all the help, Richard.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

Are you talking about removing entities from the space or components from the game, and how is it organized?

If you want a specific horizontal velocity for your projectile with a physically simulated parabola, you can have a look at this thread:
http://www.bepu-games.com/forums/viewto ... ?f=4&t=683
This sort of system can be good for tower-defense style shots because you typically have a specific horizontal (max) range, and the 'speed' of the projectile commonly refers to the horizontal speed.

Another option would be having a single 'speed' for the whole three dimensional velocity, so that you change the distance covered by changing the pitch of the shot.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Yes i'm trying to remove the entity model, space entity and the game component. They are all connected to one class. And each time my tower shoots, a new object is created which has these entities in it. But when i try to remove one, they all get removed.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

Components.Remove and (Space).remove each only remove a single instance from their respective systems; are you using another method?
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

I am also removing the EntityModel class. So i also call Components.remove(em);

So for each sphere, they have a create time, and each update it checks if it should be removed. But when one of them is ready, they all get removed.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

I would recommend putting a breakpoint in your code where the lifespan expires, step through it, and see when something bad happens in the debugger.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Figured it out, i wasnt computing my sphere age correctly, apparently the TimeSpan class cannot be null... didnt know that.

anyways, i did look at the tank shooting method you were talking about, but for some reason the vector i point it at is not where the sphere goes...
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

What does it do? If you work out the equations by hand, you can get a good idea of what the values are supposed to be. That way, you can step through with the debugger and see if anything doesn't quite match up.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Well it does shoot it, but no matter what i change the "target" vector to, it always shoots in the same direction.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

That sounds like it would be pretty easy to spot by stepping through the code line-by-line in the relevant function, and verifying each individual value. I suspect if you used the code off of that thread (with the followup modification of (1/2) -> .5f), the problem will be that the positions aren't quite what you expect them to be.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Figured it out, you were right, it was some position problems.

Thanks
Post Reply