Hey guys. I have started adding weapons to my game. All the weapons in the game will be children of a weapon holder. This weapon holder has a script for movements, so the weapons move when the player walks. Currently I’m trying to make my weapon holder delay it’s rotation, so the weapons wouldn’t look so static.
I wan’t to do something like Avert Fate’s weapon movement.
I already made my weapon move when I walk with some trigonometry, but I can’t get to delay it’s rotation. I did it with Input.GetAxis(), but the result isn’t really nice.
Here’s what I’ve done so far:
var offsettime = 0.0;
var offsettemp = 0.0;
var offsettempY = 0.0;
var offsetY = 0.0;
var offsetX = 0.0;
function Update () {
//Rotation Delaying
var delayPosX = -Input.GetAxis("Mouse X")/ 500;
var delayPosY = -Input.GetAxis("Mouse Y")/ 500;
transform.localPosition = Vector3(delayPosX + offsetX, delayPosY + offsetY, 0);
//Check if the player walks
if(Input.GetKey("w") || Input.GetKey("s") || Input.GetKey("a") || Input.GetKey("d"))
{
MoveWeapon();
}
}
function Start () {
MoveWeapon();
}
function MoveWeapon () {
if(offsettime < Time.time)
{
offsettemp += Time.deltaTime * 8;
offsettempY += Time.deltaTime * 16;
offsettime = Time.time + 0.01;
}
offsetY = Mathf.Sin(offsettempY) / 1000;
offsetX = Mathf.Sin(offsettemp) / 1000;
}
Any help with this? I don’t even know in theory how that delaying works, never done such thing.
Yes you could use animation instead.
I use an idle animation which looks really nice. However you could also have a sidestep animation to make it move slightly to one side when you sidestep.
If thats just a brief few frames it would look realistic.
I really recommend animation above coding. For instance I have a smooth aim script for aiming down the sights, this doesnt look that good because coding makes quite a linear sequence.
You have a point, but I think, that coding this would be better. For example I can make four animations for upwards, downwards, left and right, but what about if I’m slightly moving to the right/ left side and looking upwards pretty fast? I’ll have to make an animation to suite each type of movement the player makes with the camera. I think this could be done to look pretty nice, for example my weapon movement animation thing is in the script and the weapon moves really smooth - exactly like an animation, only each time, slightly different (gotta make a video of it). I’m still getting used to javascript and I’m sure it’s pretty simple, don’t know why I’m stuck at this.
You could use cross fade to get the animations to blend when turning and looking up at the same time. 
Well, I still think scripting would be the easiest way, but if you all suggest doing that with animations, than I should definitely check it out! 
I am very interested in delay… I`m trying to make something like this:
But still without any luck…
For run and walk i made animations with unity animator… Looks very good!
your script works, but need some correction… I hope that somebody could help 
Yeah, it works, but it’s pretty glitchy. I’m pretty sure it could be done with scripting and I’ll keep trying and thinking on it, but if there’s no success, I’ll try with animations.
Alright guys, so it really has to be done with animating. This morning I wrote some code for this and it worked, but it really didn’t look nice. Everything was really sudden. I’m sure that it could be done using trigonometry, but yeah, animating will be best.
whats new with delay? I still think that best way will be use scripts, but if you made delay with animations (and they works), can you show us how it looks? 
Well I tested a script and I problem that I find is that the weapon stays in a middle of the main camera. (At 0, 0, 0)
There is a way to fix this but not in a script. What I did is;
I placed the object with a script at 0, 0, 0.
Created 2 empty GameObjects.
Binded the weapon and GameObject1 both in full zero.
Binded GameObject1 with a weapon to GameObject2 and carefully moved it to a player.
I hope this will help. It did for me.