FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionhead bobbing script Is very important in personal(free)

more_horiz
head bobbing script Is very important in personal free


this script camera to move like your head when you walk in real life

dont forget subscribe my chanels youtube pleez [You must be registered and logged in to see this link.]

private var timer = 0.0;
var bobbingSpeed = 0.18;
var bobbingAmount = 0.2;
var midpoint = 2.0;

function Update () {
waveslice = 0.0;
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) {
timer = 0.0;
}
else {
waveslice = Mathf.Sin(timer);
timer = timer + bobbingSpeed;
if (timer > Mathf.PI * 2) {
timer = timer - (Mathf.PI * 2);
}
}
if (waveslice != 0) {
translateChange = waveslice * bobbingAmount;
totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0);
translateChange = totalAxes * translateChange;
transform.localPosition.y = midpoint + translateChange;
}
else {
transform.localPosition.y = midpoint;
}
}

descriptionRe: head bobbing script Is very important in personal(free)

more_horiz
Wow, 12 errors.

descriptionRe: head bobbing script Is very important in personal(free)

more_horiz
[You must be registered and logged in to see this link.] wrote:
Wow, 12 errors.

Sometimes there's problems with forums and indenting.  I'll make a pastebin myself later with corrections if you're that interested.

EDIT: Ok, this has clearly been extracted from another script with the headbob since some variables are missing, will still make a pastebin with *corrected* script.

EDIT: Hey, OP, this script works REALLY nicely! You just made a couple of minor(ish) errors when you posted the script here.
The *corrected* script is:

Code:

#pragma strict

/*
Code by Zino2K, corrected as a standalone script by Zino2K and Xezno.
For any information contact Zino2K on Unityninja.net
*/
private var timer = 0.0;
var bobbingSpeed = 0.18;
var bobbingAmount = 0.2;
var midpoint = 2.0;
private var waveslice = 0.0;
private var horizontal = 0.0;
private var vertical = 0.0;
private var translateChange = 0.0;
private var totalAxes = 0.0;

function Update () {
waveslice = 0.0;
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) {
timer = 0.0;
}
else {
waveslice = Mathf.Sin(timer);
timer = timer + bobbingSpeed;
if (timer > Mathf.PI * 2) {
timer = timer - (Mathf.PI * 2);
}
}
if (waveslice != 0) {
translateChange = waveslice * bobbingAmount;
totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0);
translateChange = totalAxes * translateChange;
transform.localPosition.y = midpoint + translateChange;
}
else {
transform.localPosition.y = midpoint;
}
}

Not to offend you, of course, since you only missed a couple of variables.  Nothing much to worry about, happens to the best of us Rolling Eyes .  

Just attach this to your camera and it does everything for you.  You can adjust things such as the speed of the bobbing and the amount in-editor without editing code.

_________________
four kbytes of data | working on an untitled fps game
Permissions in this forum:
You cannot reply to topics in this forum