Posted by: omega
Date posted: Apr 28 2003 User Rating: N/A | Number of views: 2829 Number of comments: 13 | Description: (Extension to X-0ut's custom model tut) |
While reading through X-0uts tutorial I decided that i should write a simple tutorial on UTIL_SetSize() (essentially). This tutorial will show you how to automatically set any entities bounding box for entity to entity collision, based on the model's box. This could be useful for weapon pickups other items, and most definitely the most important: monsters!
The significant changes we will be making are contained in cbase.h, So open it up and do the following: include studio.h with the rest of the includes.
| | | #include "../engine/studio.h"
|
Next, somewhere inside the CBaseEntity class, add this function:
| | | void SetModelCollisionBox() { studiohdr_t *pstudiohdr; pstudiohdr = (studiohdr_t*)GET_MODEL_PTR( ENT(pev) );
if (pstudiohdr == NULL) { ALERT(at_console,"Unable to fetch model pointer!\n"); return; } mstudioseqdesc_t *pseqdesc; pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex); UTIL_SetSize(pev,pseqdesc[ pev->sequence ].bbmin,pseqdesc[ pev->sequence ].bbmax);
}
|
Now, any time you wish to set the entities collision box based on its models bounds; Simply add a call to: SetModelCollisionBox(); inside one of the entities functions. Usually you will want to do this inside Spawn, at the bottom of the function. If you know that the entities mesh/bounding box scales up in different sequences, you'll want to call this every time the animation changes to make sure it's correct.
Following off of X-0ut's tutorial, to demonstrate this we will modify the spawn function.
| | | void CModel::Spawn( void ) { ---[SNIP]--- SetThink(Animate); pev->nextthink = gpGlobals->time+0.5; SetModelCollisionBox(); }
|
Simple huh? Gotta love simple tutorials. I need to write something more intermediate, without direct code blocks =D |
|
User Comments
Showing comments 1-13
|
I just updated this tutorial to fix a minor bug, and reformat it with the C++ tags. |
|
Nice, just what i needed for my env_models.
Note: If you set a boundingbox in the qc, using $bbox, you can use pstudiohdr->max and pstudiohdr->min to get the boundingbox. This is very usefull if you want a smaller boundingbox than the model. We use it to put the box around the branch of a tree, but not around the leaves. |
|
|
nice on omega i'll be useing this when i rebild my mod |
|
Hello OMEGA. I´ve found this when I try to compile your tutorial:
--------------------Configuration: hl - Win32 Debug-------------------- Compiling... sentinel.cpp D:\JUEGOS\SIERRA\PROGRAMAS DESARROLLO MODS\HLSDK2.3\Single-Player Source\dlls\yourmonster.cpp(607) : error C2065: 'Animate' : undeclared identifier D:\JUEGOS\SIERRA\PROGRAMAS DESARROLLO MODS\HLSDK2.3\Single-Player Source\dlls\yourmonster.cpp(607) : error C2440: 'static_cast' : cannot convert from 'int' to 'void (__thiscall CBaseEntity::*)(void)' There are no conversions from integral values to pointer-to-member values Error executing cl.exe.
hl.dll - 2 error(s), 0 warning(s)
I was completely lost about what was the problem, then I realized that the compiler asked for a function, then I added under:
int CYourmonster :: Classify ( void )
this:
//------------------------------------------------------------ // Omega´s Set Collision Box by model Tutorial //------------------------------------------------------------
void CYourmonster::Animate( void ) { pev->nextthink = gpGlobals->time + 0.5; }
and, of course in the function declarations under :
void BecomeDead(void);
I added.
void EXPORT Animate (void);
And all goes fine, it compiled without problems.Edited by MIFUNE on Oct 14 2005, 10:42:38
|
|
|
Excuse me, I wrote that because I want to know If adding that function I should screw something... |
|
wait, no it's not.
that little bit of code was from x-0ut's tutorial, with my tutorial code added in. try reading it better next time ;) |
|
|
you say that "that's what you're supposed to do"...OMG, I screwed something , no?. Excuse me if I´m misunderstanding you, but my english is not very good. The monster works fine, BTW. I fear of a breakdown or similar because ( if Persuter reads this he´ll curse me for sure :D ) I didn´t debugged the code.Edited by MIFUNE on Oct 14 2005, 12:49:30
|
|
just add the SetModelCollisionBox(); function to your spawn somewhere. the animate thing was from x-0ut's tutorial; not mine. |
|
So I must add X-OUT´s part into the SPAWN part.
I´ll do it. :) Thanks a lot.Edited by MIFUNE on Oct 14 2005, 13:56:42
|
|
NOOOO!!!!! x-0ut's thing is a TOTALLY SEPERATE ENTITY!!! i used his as a base for the *EXAMPLE*!!!! |
|
|
Oh...so, I must left the things I did untouched?. Oh, crap!! Sorry, It´s clear that X-Out´s code must go in cbase.h ,what a silly I am!! Thanks Omega for your patience. ^_^ |
|
oh my god.
just take the function SetModelCollisionBox(); add it to CBaseEntity; DONE! now in your spawn function for whatever you wanna use it on, use SetModelCollisionBox(); *IGNORE ALL OF THE REST OF THE GODDAMNED CODE IN THIS TUTORIAL.* obviously you don't understand english very well. and im getting tired of repeating myself. |
|
|
Sorry, Omega, I didn´t want to piss you off. I understand you now ( C++ newbie + english level 3 ( of 6 ) = disaster ) .Edited by MIFUNE on Oct 14 2005, 16:29:26
|
|
You must register to post a comment. If you have already registered, you must login.
|
296 Approved Articless
5 Pending Articles
3940 Registered Members
2 People Online (23 guests)
|
|