Game Development Community

ShapeBase / GameBase classes

by Robert Brower · in Torque Game Engine · 01/14/2003 (8:10 pm) · 5 replies

I have tried a couple of different ways to get floating asteroids into my space game prototype.

1. The first thing I tried was to use AIPlayer and I wrote a 2nd spawnPlayer() function and called it spawnAsteroid(). This function just created a AIPlayer and used the asteroid datablock. I also wrote onLeaveMissionArea() for asteroid so that i could calculate the reentry point of the object when it leaves the mission area so that the asteroids would wrap around to the opposite side of the mission area and reenter. I added code to spawn asteroids at every marker location in a given simgroup and applied a random impulse to them after they were created to get them moving.

The problems I had with this were that the CrossbowProjectile and my ship weren't very good at detecting collisions with the asteroids. Also, someone told me that since I'm using a random impulse and that they are just dumb rocks floating that I did not need the overhead of the AIConnection class... so I switched to method 2.

2. I changed my script so that Asteroid datablock was a ShapeBase object. All of the spawning code works, the asteroids are spawned and are at the marker locations but I cannot see them. If I make them static shapes I can see them but I can't apply a random impulse.

The problems here are that I can't see the asteroids. I can confirm that they are there with echo() and i can see the object id's created by the keyword new() but they aren't visible.

My question is, is there a way to use ShapeBase as is to create objects that simply float around the mission area in zero G? I have the zero G feature added to shapebase. All I need to do is spawn a visible object that collides with other objects like ships, projectiles, other asteroids and have it float around the mission area so that I can shoot at them =)

If not, is there any guides to how to derive from gamebase or shapebase? I am not sure what functions I need to override, etc. what all is required. This gets down to the nuts and bolt of a lot of what has confused me for a long time. Any help here would be GREATLY appreciated.

Thanks a lot =)

Robert

#1
01/14/2003 (8:22 pm)
Robert, The AIPlayer class has not been an AIConnection for many months ...
#2
01/14/2003 (8:43 pm)
look for one of Melv's resources called fxRender . . . all should be explained in that.
#3
01/14/2003 (9:47 pm)
Thanks guys, both very good responses. I'll look at melv's stuff right now, although if my memory serves me it is sceneobject based and not ShapeBase based like Player is. ShapeBase is the class I want to use. i wish there was a tutorial on creating new shapebase derived classes. As for AIPlayer, why would my vehicle and projectiles be so sketchy with the collisions is my next thing to look at after that.
#4
01/15/2003 (5:37 pm)
I second that tutorial request :)

Mike
#5
01/15/2003 (6:05 pm)
I started diving into gamebase tonight by copying projectile.cc and .h into target.cc and .h and renaming everything. I am removing a little of the code. Eventually I will have a generic target object which you can spawn and send in some direction so that you can shoot at it and it can explode, etc. Right now I am trying to learn why my gamebase derived class Target::onCollision() function is never called. Miller, if you want to work on this with me come into IRC and talk to me there. A lot of people could benefit from this I think.


The Projectile class detects collisions by performing a ray cast from old position to new. This is why I wasn't getting any collisions. If I carefully position my space ship onto the origin of the asteroid then the collision is detected because the ray cast returns my ship.

Shapebase has a far more complex collision detection mechanism which I am going to try to work into my new class. It doesn't look easy.



I wound up using a container radius search instead of the ray cast and it seems to work great. It detects a projectile collision several times as the projectile passes through it. My ship is also blowing up when I crash into an asteroid. A question I have is... When I shoot a projectile from my spaceship at an asteroid, should both the asteroid::onCollision and the projectile::onCollision get called or just the asteroid::onCollision(). Currently only the asteroid::onCollision() gets called. In Projectile::processTick() the castRay function says there are no collisions. I don't know why.