Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by DincaAlin · Sep 13, 2015 at 10:10 PM · script.unity 4.6unity multiplayer

Multiplyaer FPS sprint speed does not work

I HAVE THIS WARNING: Assets/Scripts/FirstPersonController.cs(65,23): warning CS0219: The variable `speed' is assigned but its value is never used I FOLLOWED THE MIKE GEIG TUTORIAL ABOUT MERRY FRAGMAS AND BECAUSE OF THIS WARNING I CAN'T SPRINT. THE ANIMATION WORK'S, BUT MY SPEED DO NOT INCREASE. HERE IS THE SCRIPT:

using UnityEngine; using System.Collections;

[RequireComponent (typeof(CharacterController))] public class FirstPersonController : MonoBehaviour {

 public bool walkByDefault = true;
 public float runSpeed = 8.0f;
 public float movementSpeed = 5.0f;
 public float mouseSensitivity = 6.0f;
 public float upDownRange = 60.0f;
 public float jumpSpeed = 20f;
 float verticalVelocity = 0;
 CharacterController characterController;

 Animator anim;
 // Use this for initialization
 void Start () 
 {
     Screen.lockCursor = true;
     characterController = GetComponent<CharacterController> ();

 }
 
 // Update is called once per frame
 void Update () 
 {
     //Rotation

     float rotLeftRight = Input.GetAxis("Mouse X") * mouseSensitivity;
     transform.Rotate (0, rotLeftRight, 0);

     float rotUpDown = Input.GetAxis("Mouse Y") * mouseSensitivity;

     float currentUpDown = Camera.main.transform.rotation.eulerAngles.x;
     float desiredUpDown = currentUpDown - rotUpDown;


     //desiredUpDown = Mathf.Clamp (desiredUpDown, -upDownRange, upDownRange);

     Camera.main.transform.localRotation = Quaternion.Euler(desiredUpDown, 0, 0);

     //Movement
     float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
     float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;

     verticalVelocity += Physics.gravity.y * Time.deltaTime;

     if ( characterController.isGrounded && Input.GetButtonDown ("Jump")) {
         verticalVelocity = jumpSpeed;
     }

     Vector3 speed = new Vector3 ( sideSpeed, verticalVelocity, forwardSpeed );

     speed = transform.rotation * speed;


     characterController.Move ( speed * Time.deltaTime);

     anim = GetComponentInChildren<Animator> ();
 }

 public void LateUpdate () {

     float speed = runSpeed;

 #if !MOBILE_INPUT
 
 // On standalone builds, walk/run speed is modified by a key press.
 // We select appropriate speed based on whether we're walking by default, and whether the walk/run toggle button is pressed:
     bool walkOrRun =  Input.GetKey(KeyCode.LeftShift);
     bool aim =Input.GetButton ("Fire2");

     if(aim)
         walkOrRun =false;

     speed = walkByDefault ? (walkOrRun ? runSpeed : movementSpeed) : (walkOrRun ? movementSpeed : runSpeed);
 // On mobile, it's controlled in analogue fashion by the v input value, and therefore needs no special handling.
     anim.SetBool ("Sprint" , walkOrRun);
     anim.SetBool ("Aim", aim);

 #endif
 }

}

ANY IDEAS?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Glurth · Sep 13, 2015 at 10:21 PM

You check for walkOrRun, and adjust speed appropriately in LateUpdate()

 float speed = runSpeed;
 ...
 if(aim)
     walkOrRun =false;
 speed = walkByDefault ? (walkOrRun ? runSpeed : movementSpeed) : (walkOrRun ? movementSpeed : runSpeed);

but you do NOT do this in Update(), which is where you actually move the character.

  Vector3 speed = new Vector3 ( sideSpeed, verticalVelocity, forwardSpeed );
      speed = transform.rotation * speed;
      //need to adjust for walk or run here
      characterController.Move ( speed * Time.deltaTime);



Comment
Add comment · Show 4 · 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
avatar image DincaAlin · Sep 14, 2015 at 08:55 AM 0
Share

Can you explain me simple, please? Because I do not understand very good what you say. I need to move some script lines or what?

avatar image Glurth DincaAlin · Sep 16, 2015 at 02:31 PM 0
Share

You need to add some of the code the that you have in LateUpdate(), to your Update() function.

In paricular, you need to check if the character is running or walking: and based on that result, assign a speed(magnitude) of runSpeed or movementSpeed. I don't know if you want to adjust forwardSpeed& 'sideSpeed', or speed, that will be up to you.

avatar image DincaAlin Glurth · Sep 17, 2015 at 01:49 PM 0
Share

Well I have followed the $$anonymous$$erry Fragmas tutorial and I write what the speaker said. Here is the tutorial: https://unity3d.com/learn/tutorials/modules/intermediate/live-training-archive/merry-fragmas-multiplayer-fps

Show more comments

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

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to assign GameObject to Script? 1 Answer

[Help] how do I reference/access another script in unity C# 2 Answers

How to assign Instantiated object through script? 1 Answer

Have object fly towards camera 0 Answers

Animation only plays in one of the objects 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