Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by _HappyGoLucky · Sep 04, 2014 at 04:26 AM · javascriptheadbob

Headbobbing

I am trying to put a headbobbing script into a sprinting script to increase the bob amount and speed and I come across it saying headbob does not denote a valid type

Sprinting code Javascript

 #pragma strict
  
 var walkSpeed : float = 5; // Regular speed
 var sprintSpeed : float = 10; // Run speed
 var bobamounta : float = 0.1; // Walking bob amount
 var bobamountb : float = 0.2; // Headbobbing amount
 var bobbingSpeeda = 0.1;
 var bobbingSpeedb = 0.2;
 private var charMotor : CharacterMotor;
 private var charController : CharacterController;
 private var headbob : headbob;
  
 function Start () 
 {
     charMotor = GetComponent(CharacterMotor);
     charController = GetComponent(CharacterController);
     headbob = GetComponent(headbob);
 }
  
 function Update () 
 {
     //Making the actual speed var
     var speed = walkSpeed;
     
     var bobbingSpeeda = bobbingSpeedb;
     
     var bobbingAmount = bobamounta;
  
     //Checking for oppertunity to sprint
     if(charController != null)
     {
         if ( charController.isGrounded && Input.GetKey("left shift"))
         {
             //changing the speed to sprint
             speed = sprintSpeed;
             
             bobbingSpeed = bobbingSpeedb;
             
             bobbingAmount = bobamountb;
         }
     }
     else print("charController component not found.");
  
     if(charMotor != null)
         charMotor.movement.maxForwardSpeed = speed; //Setting the speed
     else print("charMotor component not found.");
 }


Headbob script javascript

  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; 
     } 
  }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Redeemer86 · Sep 04, 2014 at 04:34 AM 0
Share

I am confused about what you exactly intend to do. And what sort of a declaration is headbob ? Is it a class definition ? I dont think it's something inbuilt in Unity. Are you trying to use a custom class "headbob". If so how is it defined ?

avatar image _HappyGoLucky · Sep 04, 2014 at 07:30 PM 0
Share

I want to make the headbobbing go faster and a little more intense while you are sprinting.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jokim · Sep 04, 2014 at 07:54 PM

You say "Headbob script" but you declare it in code as headbob.....

do a spellcheck and make sure both are exactly identical : code is very case sensitive.

 private var headbob : Headbob;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Accessing A Variable Across Script In A Child Object 0 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Head bobbing camera movement (Javascript, home made) 1 Answer

create shortest AI path from/to object. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges