Shard Posted May 29, 2010 Share Posted May 29, 2010 When I shoot the gun, I need to check if I hit a Character type object. Unfortunately, I can't compare the returned entity to check if I hit a Character object or a Vehicle object because it is a byte*. How do you guys determine what you have hit? Example; //Character class Character { TMesh mesh = LoadMesh("abstract::player.gmf"); SetEntityUserData(this); }; [/code ]//Shoot Function [code]void Character::Shoot() { if(currentWeapon->canShoot) { currentWeapon->canShoot = false; TPick target; if(user->isPlayer) EntityPick(&target,frameWork->GetMain().GetCamera(),range); else EntityPick(&target,user->head,range); if(target.entity != NULL) { Character *hitTarget = (Character*) GetEntityUserData(target.entity); //<------- How do I check if I'm hitting a character object or just an object casted to a character type? } } } A friend of mine suggested that I compare the sizeof(Character) to the sizeof(hitTarget). I thought this would work at first, but then I realized that since I'm casting to a character type from byte*, the size of hitTarget would always be the same as a Character type. What do I do here? Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
Pixel Perfect Posted May 29, 2010 Share Posted May 29, 2010 Just of the top of my head you could use SetEntityUserData to store a struct which contains the class pointer as one element and the class type as the 2nd. for example struct objectDetails { byte* objectPointer; int objectType; } where for instance objectTypes are 0 = character, 1 = vehicle so on and so forth Then conditionally cast the byte* objectPointer to the class based on the objectType. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
Flexman Posted May 29, 2010 Share Posted May 29, 2010 Just be aware if you're making a multi-player game, be careful using pointers in entity user data. A remote machine won't be able to match the pointer to anything valid. Just something to be aware of. Quote 6600 2.4G / GTX 460 280.26 / 4GB Windows 7 Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT Tricubic Studios Ltd. ~ Combat Helo Link to comment Share on other sites More sharing options...
Pixel Perfect Posted May 29, 2010 Share Posted May 29, 2010 That's a good point Flexman. Assuming it's not a multiuser game though: Another way that has occured to me is to have base class that all of your dynamic game objects classes are subsequently derived from (this is what I do in my game engine framework). The base class contains common data items such as the EntityID of the objects, the position, rotation, objectType etc. As all of your higher game objects classes (Vehicles, NPCs and so on) are derived from this base class then their pointers can be assigned to pointers of the base class. So you effectively have a universal way of casting a base class pointer to any of the derived object classes. The problem with this is that it only allows access to the methods and variables inherited from the base class but if you made one of those a classType variable in which you stored the derived class type at the time its created then you could access this and again conditionally cast the same base pointer to the devived class type getting full access. Conversely, you could assign a different EntityType for each type of your dynamic game object types and distinguish between them using GetEntityType(PickedEntity) in order to apply the correct cast. Just some food for thought. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
ZioRed Posted May 29, 2010 Share Posted May 29, 2010 Cannot simply use different collision types for the objects and so filter directly them with EntityPick (or also checking their entity type after picking)? Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Pixel Perfect Posted May 29, 2010 Share Posted May 29, 2010 Cannot simply use different collision types for the objects and so filter directly them with EntityPick (or also checking their entity type after picking)? Didn't I just say that lol. No harm in repeating it I guess Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
ZioRed Posted May 29, 2010 Share Posted May 29, 2010 Oops sorry I didn't noticed your last post Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Shard Posted May 30, 2010 Author Share Posted May 30, 2010 Conversely, you could assign a different EntityType for each type of your dynamic game object types and distinguish between them using GetEntityType(PickedEntity) in order to apply the correct cast. Cannot simply use different collision types for the objects and so filter directly them with EntityPick (or also checking their entity type after picking)? Mind = Blown. Didn't even think of this. Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.