Page 1 of 1
Melee Weapons Question
Posted: Wed Apr 21, 2004 7:30 am
by Kuros
I thought this might be a good place to ask this question, since there seems to be very little documention on the web about it, and the ChaosUT team is the only one I know working on melee weapons.
Are you guys aware of any melee weapon example code or somesuch? I'm (trying) to play with getting a few working, but the UT2k3 code for things like hit detection and such doesn't work with UT2k4, unfortuantly.
Links or example code or anything along those lines would be greatly appreciated.
Posted: Wed Apr 21, 2004 11:46 am
by jb
Kuros,
there is no documentation that I could find for melee weapons on UT2k3. We had to do all of our work more or less from the ground up. We did take a quick peak at old Rune Code. But that game was designed around UT/Unreal so most of it did not apply. I have been wanting to write a wiki page on how we did ours and give a working example. Just never have gotten around to it. I promise to do that soobn. If you have any questions feel free to ask.
Posted: Wed Apr 21, 2004 11:48 am
by Kuros
Ok, cool. I'll post my current attempt. I took the original code from a post on 3D Buzz, but it was for UT2k3. I got it to compile under UT2k4, but its not working how I want, atm. here is a copy of the post:
Code: Select all
Melee Hit Detection - Not detecting =/
I took the code from the "Hand 2 Hand" post a pages back, and got it to compile under UT2k4. Here is the code:
code:
function MeleeTargetting()
{
local vector HitLoc, HitNorm, End, X, Y, Z, Start;
local Actor Other;
local rotator Aim;
// Get vectors for where the player is aiming on each axis
GetAxes(Pawn(Owner).GetViewRotation(), X, Y, Z);
// Calculate starting location
Start = Owner.Location + Pawn(Owner).CalcDrawOffset(Weapon) +
Pawn(Owner).Weapon.EffectOffset.X * X + Pawn(Owner).Weapon.EffectOffset.Y * Y
+ Pawn(Owner).Weapon.EffectOffset.Z * Z;
Aim = AdjustAim(Start, AimError);
// Using an arbitrary range of 100 UUs
End = Owner.Location + (5000 * vector(Aim));
// Using TraceActors and a 10x10x10 cube for the extents
foreach Owner.TraceActors(class'Actor', Other, HitLoc, HitNorm, End, Start,
vect(10000.0, 10000.0, 10000.0)) {
}
Log("Found contact! -K");
Log("Name of: ");
Log(Pawn(Other).Name);
}
Now, when I shoot the weapon, I get this in the log:
ScriptLog: Found contact! -K
ScriptLog: Name of:
Warning: PuncherFire DM-1on1-Albatross.puncher.PuncherFire0 (Function puncher.PuncherFire.MeleeTargetting:017A) Accessed None 'Other'
ScriptLog: None
It is apparently not finding collision with any actor. I can be right on top of the bot, pointing straight at him, and I still get no name, or anything. I can't find any errors in the hit detection or TraceActors.
Any help is greatly appreciated.
Posted: Wed Apr 21, 2004 11:57 am
by jb
Try this:
Code: Select all
function MeleeTargetting()
{
local vector HitLoc, HitNorm, End, X, Y, Z, Start;
local Actor Other;
local rotator Aim;
// Get vectors for where the player is aiming on each axis
GetAxes(Instigator.GetViewRotation(), X, Y, Z);
// Calculate starting location
Start = Instigator.Location + Instigator.EyePosition() + X*Instigator.CollisionRadius;
Aim = AdjustAim(Start, AimError);
// Using an arbitrary range of 100 UUs
X = Vector(Aim);
EndTrace = StartTrace + 1000 * X;
// See if we hit any thing
Other = Trace(HitLocation, HitNormal, EndTrace, StartTrace, true);
If (Other != None)
{
Log("Found contact! -K");
Log("Name of: ");
Log(Pawn(Other).Name);
}
}
It may not be as accurate but it should work just fine. I think the problem was how the traceactors was set up.....
Posted: Wed Apr 21, 2004 12:12 pm
by Kuros
Wee, much better! Thanks!
Here is the log output:
ScriptLog: Found contact! -K
ScriptLog: Name of:
ScriptLog: xPawn
I guess I have to go another layer deeper to get the actual name, but still, very cool!
Posted: Wed Apr 21, 2004 12:14 pm
by jb
Glad its working for you. Again feel free to tweak it and find out what breaks it and what makes it better.
Posted: Wed Apr 21, 2004 12:15 pm
by jb
BTW you can cut down the log to a single step:
Log("Name of: " @Pawn(Other).Name);
Posted: Wed Apr 21, 2004 12:18 pm
by Kuros
Oo, thats the macro I was lookin for!
I'm used to python where I can do Log("A String "+variable).
I'm remembering why I hate C++ strings. =P