Download

Help center weapon model on view

Hello my dear UDK Brothers. There is a long time I don’t ask my folks here anymore, it’s because I learned a lot by myself through searching on the legacy EPIC Game Forums, also on the UDN Documentation.

Many of you who are following my game’s development here have seen a lot of improvements I have done on my game, and also have seen that my game is already on steam, with a brand new and updated demo:

But the game on it’s current state, which I planned to release in December but I think I will need to delay it to January, has a lot of the demo’s bug already fixed and many other improvements.

However, something steam players complained a lot is the weapons alignment in first person view mode (my game has option to alternate between 1st person view and 3rd person view).

I am using all UTGame base scripts, like UTPlayer, UTWeapon and so on. I have changed many things on these base classes, besides having created many custom classes for my game. I don’t know if this is the default behaviour of guns in UDK, or it is because some changes I have made, but in my game’s first person view mode the guns move to the sides whenever you move the camera, I mean, they dont stay fixed, aligned with the crosshair (this should be the right behaviour), but whenever you shoot, they realign, kinda snap to the crosshair. I made a fire animation for the guns on 3dsmax, it is a very simple back-forth animation done with 5 keyframes, so I think this is why the weapons snap back to the crosshair whenever you shoot.

I made this small video so you can see the problem:

ANY HELP IS VERY APPRECIATED.

Thanks in advance.

Hey it is not the normal behavior, and I can see why they complain it breaks the smoothness of the FPS control the eye and brain expect a different outcome then you are producing. My UDK weapon do not do this and they are base on the original UT3 code

You could try comparing these scripts or load the assets up test this sniper. Note that if you changed something in the parents then this gun will act the same and may point you to parent
insight to the error and if you need to change something in the parent you should just know you are inherit and just override functions in your new class because it is less dangerous leads to a bad code base

UDK Sniper Rifle

The weapon actor positioning is handled in SetPosition() in your weapon class (which gets called every tick). UT has some code in there to interpolate the weapon’s rotation with the camera view:

// Add some rotation leading
	if (Holder.Controller != None)
	{
		FinalRotation.Yaw = LagRot(NewRotation.Yaw & 65535, LastRotation.Yaw & 65535, MaxYawLag, 0);
		FinalRotation.Pitch = LagRot(NewRotation.Pitch & 65535, LastRotation.Pitch & 65535, MaxPitchLag, 1);
		FinalRotation.Roll = NewRotation.Roll;
	}
	else
	{
		FinalRotation = NewRotation;
	}

For some reason in your game the interpolation is not ticking when you’re camera is not moving.

Add some logging in this section of code to find why it’s not re-centering when your camera stops moving.

Thanks mate for the repply. Yeah, this problem happens even with default UDK Guns, like the rocket launcher, the link gun and so on.

Thanks dude, I will take a look again on my UTWeapon code, it may be something I changed there in the beginning but I am not remembering it right now.

I was playing with this function and indeed it makes sense to rotate the weapon to follow the player camera movement. However, I think if I could bind, lock the weapon rotation to the player’s camera rotation, it would solve my problem. Do you know how can I do it?

Thank you very much.

If you wanted it just fixed, it would be something like this i guess:

local vector newRotation;
newRotation = Holder.GetViewRotation();
SetRotation(newRotation);

I don’t think that’s what you want though. Having a weapon that is just statically fixed in place to the camera would feel rather floaty for player movement.

Hello my friend, thanks for trying to help me. But now it is even worse.

The UTWeapon already has the variable newRotation, but it is a rotator and not a vector.

So I declared your variable as newRotationWeapon as a vector, then I changed that part of the script to this

    // Add some rotation leading
    if (Holder.Controller != None)
    {
        //FinalRotation.Yaw = LagRot(NewRotation.Yaw & 65535, LastRotation.Yaw & 65535, MaxYawLag, 0);
        //FinalRotation.Pitch = LagRot(NewRotation.Pitch & 65535, LastRotation.Pitch & 65535, MaxPitchLag, 1);
        //FinalRotation.Roll = NewRotation.Roll;
		newRotationWeapon = Holder.GetViewRotation();
		SetRotation(newRotationWeapon);
    }
    else
    {
        FinalRotation = NewRotation;
    }
    LastRotUpdate = WorldInfo.TimeSeconds;
    LastRotation = NewRotation;

When I first compiled it gave me an error of type mismatch, so whenever I changed your variable to rotator

local rotator newRotationWeapon;

It compiled correctly, but this is the result. It is even worse, because now the gun does not rotate at all whenever the player moves the camera.

Thanks again for helping me bro :+1: :+1: :+1:

Yes, sorry I meant to type rotator, not vector.

You should try debugging within your SetPosition(). Verify that the Rotation of your weapon (at the end of the function) is as you expect (matching the rotation of your view).

Check that Holder.GetViewRotation() is returning a changing value as you move your character’s view.