Game Development Community

RenderCollisionBounds Woes - Crash and Burn

by Sharpie · in Torque X 3D · 04/22/2010 (1:38 pm) · 6 replies

Hi all,

I'm making a soccer game...ish. And I've got the field, got the player, got the ball. All is working well except for the collision. My field doesn't have a collision block like I thought I put around it. Bob (my player) doesn't fall through because of the MovementComponent, and runs around pretty darn realistically. But the ball falls right through the field and bounces away along the terrain I've got in the background. Any ideas on fixing that? I added the components that John's book suggested to fixing that, but unfortunately it didn't work. You think it might be because of the model itself? Or can that be coded exclusively into Torque, the collision, that is?

I'd like to put a complete box around the field, that way Bob can't run off the field, and neither can the ball. Also that the ball won't fall right through. As far as I know, Bob can still kick the ball (cause he could before), but I haven't been able to find out, because the ball always drops away immediately. Although...come to think of it...I think the field does have a collision block. Because when the soccer ball runs into it (which it does immediately, since they're spawning in the same basic spot), the ball takes off. It didn't used to do that. But how can I make the field impenetrable so that the ball stays on top of it? I guess that's my main question. :)

Thanks!

#1
04/25/2010 (7:47 pm)
Okay, so...let's try this again. I currently have the ball surviving long enough that Bob can get it through the goal and score a point. I did this by adding a T3DBox to both Bob and the field, and a T3DSphere to the ball. But the ball still sinks beneath the field eventually, and usually fairly quickly. It's like the field, while providing some sort of collision detection, is still allowing the ball through. For whatever reason. If anybody has any insight, that would be awesome. Thanks! :)
#2
04/25/2010 (9:50 pm)
Hmm...so it seems that the simple answer is to set RenderCollisionBounds to true. Except that this isn't so simple. Why? Because every time I do so, the game refuses to run. Crash and burn. I've read that I may need to chang the LightingMaterial.cs file? How do I go about doing that? I realize this is included with TorqueX, but I don't know of any way to access those files. I have the XNA Creator's Club edition, and as far as I know, I can't edit the source files.

Any ideas on workarounds would be wonderful. Thanks!
#3
04/27/2010 (7:35 pm)
? I have been able to run with the RenderCollisionBounds set to true. However as we are all learning that doesn't mean you can! Here is how I create a dude, I use a sphere not a box for my collision:

public void CreatePlayer()
        {
            //find the physics resolver
            RigidCollisionManager rigidManager = TorqueObjectDatabase.Instance.FindObject<RigidCollisionManager>("RigidManager");

            TorqueObject objPlayer = new TorqueObject();
            objPlayer.Name = "PlayerObject";

            T3DSceneComponent componentScene = new T3DSceneComponent();
            componentScene.Position = new Vector3(1220, 990, 215);
            componentScene.SceneGroup = "PlayerObject";
            objPlayer.Components.AddComponent(componentScene);

            T3DTSRenderComponent componentRender = new T3DTSRenderComponent();
            componentRender.ShapeName = @"datashapestorqueorc.dts";
            componentRender.SceneGroupName = "PlayerObject";
            objPlayer.Components.AddComponent(componentRender);

            //give the player some physics attributes, like gravity and collision
            T3DRigidComponent componentPhysics = new T3DRigidComponent();
            componentPhysics.SceneGroupName = "PlayerObject";
            componentPhysics.GravityScale = 1.5f;
            componentPhysics.Mass = 300;
            componentPhysics.RigidManager = rigidManager;
            // this seems to be the part people miss, need a collision shape
            CollisionSphereShape css = new CollisionSphereShape();
            css.Radius = 1f;
            css.Center = new Vector3(0f, 0f, 1f);
            componentPhysics.CollisionBody.AddCollisionShape(css);
            componentPhysics.RenderCollisionBounds = true;
            componentPhysics.ResolveCollisions = true;
            objPlayer.Components.AddComponent(componentPhysics);

            //add the animation component
            T3DAnimationComponent componentAnimation = new T3DAnimationComponent();
            componentAnimation.SceneGroupName = "PlayerObject";
            objPlayer.Components.AddComponent(componentAnimation);

            //add the player movement conmponent
            MovementComponent3D componentMovement = new MovementComponent3D();
            componentMovement.SceneGroupName = "PlayerObject";
            objPlayer.Components.AddComponent(componentMovement);

            //add a simple shadow component
            T3DBlobShadowCasterComponent componentShadow = new
            T3DBlobShadowCasterComponent();
            componentShadow.SceneGroupName = "PlayerObject";
            objPlayer.Components.AddComponent(componentShadow);

            TorqueObjectDatabase.Instance.Register(objPlayer);
        }
#4
04/27/2010 (7:58 pm)
Hey, thanks for your reply! I actually finally got the collision working a couple hours ago. Come to find out, it was because the Builder was creating a Sphere shape around my soccer field that I didn't realize it was creating. It gave this sphere a default radius of .65, which is like a pinpoint on my field, and it was overwriting any primitive shape I added to my field. I simply changed that in the XML, and voila! Collision detection.

I'm so excited about it, I can't quit working on it now! Ha. :)
#5
04/27/2010 (8:38 pm)
Yea the builder does that and also offsets it for some odd reason.
#6
04/27/2010 (10:21 pm)
I know, it's crazy. I keep having to remind myself, "Check the code you didn't write!" ;)