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 Eddie_Reilly · Feb 20, 2015 at 12:25 PM · c#movementphotonjumpjumping

Cant Jump ?c# please

so i am making a multiplayer game in photon and when i try and jump i just stay on the ground.

here is my code

 using UnityEngine;
 using System.Collections;
 
 public class ProjectJumpCharacterController : MonoBehaviour {
 //booleans
     public bool issprinting = false;
     public bool ShootingEnabled = false;
     public bool SprintingEnabled = false;
     public bool StaminaEnabled = false;
    
     //floats
     //b
     public float bulletImpulse = 100f;
     //g
     public float gravity = 20;
     //j
     public float jumpHeight = 12;
     //L
     public float lowgravity = 5;
     //m
     public float mouseSensitivity = 6.0f;
     public float  movespeed = 100.0f;
     //n
     public float normalspeed = 250.0f;
     //s
     public float sprintspeed = 500.0f;
     //u
     public float upDownRange = 60.0f;
     //v
     float verticalRotation = 0;
     
     //KeyCodes
     public KeyCode sprint = KeyCode.LeftShift;
 
     //GameObjects
     public GameObject bullet_prefab;
     public GameObject shootfrom;
     
     //Vectors
     private Vector3 amountToMove;
    
     void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.tag == "Low-Gravity")
         {    
             gravity = lowgravity * Time.deltaTime;    
         }
     }
 
     void OnTriggerExit(Collider other)
     {
         if (other.gameObject.tag == "Low-Gravity")
         {
             gravity = 25 *  Time.deltaTime;
         }
     }
     
     void Update()
     {
             //Walking
                 float Fspeed = Input.GetAxis("Vertical") * movespeed * Time.deltaTime;
                 float Sspeed = Input.GetAxis("Horizontal") * movespeed * Time.deltaTime;
         
                 //Declaring our Character Controller and assigning it a name        
                     CharacterController cc = transform.GetComponent<CharacterController> ();
             
                 //Rotation
                 //Rotating the camera
             
                     float rotLeftRight = Input.GetAxis ("Mouse X") * mouseSensitivity;
                     transform.Rotate (0, rotLeftRight, 0);
                     verticalRotation -= Input.GetAxis ("Mouse Y") * mouseSensitivity;
                     verticalRotation = Mathf.Clamp (verticalRotation, -upDownRange, upDownRange);
                     Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0);
             
                 //Sprinting
                 //If the player presses the sprint key it adjusts the move speed of the player 
                 //if stamina is enabled it requires stamina to be > 0 and it depletes stamina when sprinting
         
                 if (Input.GetKey (sprint) && SprintingEnabled == true)
                 {
                         issprinting = true;
                 }
         
                 if (Input.GetKeyUp (sprint))
                 {
                         issprinting = false;
                 }
 
         if (issprinting == true  && SprintingEnabled == true)
         {
             movespeed = sprintspeed;
         }
 
         if (issprinting == false ) 
         {
             movespeed = normalspeed;
         }
         
         //Jumping
         if (cc.isGrounded)
         {
             amountToMove.y = 0;
             
             if (Input.GetButtonDown ("Jump"))
             {
                 amountToMove.y = jumpHeight *Time.deltaTime;    
             }    
         }
         
         if ((cc.collisionFlags & CollisionFlags.Above) != 0)
         { 
             if(amountToMove.y > 0)
             {
                 amountToMove.y =  -gravity;
             }    
         }
            
         //getting the cc to move
         amountToMove.x = Sspeed;
         amountToMove.z = Fspeed;
         amountToMove.y -= gravity;    
         amountToMove = transform.rotation * amountToMove;
         cc.Move (amountToMove);
         
         //Shooting
         if (Input.GetButtonDown ("Fire1") && ShootingEnabled == true)
         {
             GameObject thebullet = (GameObject)PhotonNetwork.Instantiate ("bullet 1", shootfrom.transform.position, shootfrom.transform.rotation, 0);
             thebullet.rigidbody.AddForce (shootfrom.transform.forward * bulletImpulse, ForceMode.Impulse);    
         }
 }

if i remove time.deltatime on the jumping part i go really high really fast and then back down really fast it just pops up and down

i need to fix this fast! please help me

Comment
Add comment · Show 4
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 meat5000 ♦ · Feb 20, 2015 at 03:18 AM 0
Share

Please take out the blank spaces from your code

avatar image Eddie_Reilly · Feb 20, 2015 at 04:55 AM 0
Share

k i did it

avatar image hexagonius · Feb 20, 2015 at 01:01 PM 0
Share

$$anonymous$$aybe you're missing Start() where you set gravity to 20 * Time.deltaTime. That only seem to happen once you trigger.

avatar image meat5000 ♦ · Feb 20, 2015 at 01:17 PM 1
Share

k i did it

You know what they say: If you want a job done right, do it yourself -_-

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by siaran · Feb 20, 2015 at 01:36 PM

I think the problem is here:

 //getting the cc to move
 amountToMove.x = Sspeed;
 amountToMove.z = Fspeed;
 amountToMove.y -= gravity;
 amountToMove = transform.rotation * amountToMove;
 cc.Move (amountToMove);

You set the amountToMove.y to -gravity just before you call move, regardless of if the player has pressed Jump.

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
avatar image
0

Answer by hexagonius · Feb 20, 2015 at 01:53 PM

In line 107 your setting y to a small amount of Jumpheight. Remove * Time.deltaTime here.

In line 122 you're substracting the full gravity value. add * Time.deltaTime here.

Comment
Add comment · Show 1 · 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 Eddie_Reilly · Feb 20, 2015 at 04:51 PM 0
Share

but now the jumping just makes me pop up and down really fast

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't get character to Jump on the Y Axis (C#) 2 Answers

I cant make my character jump ?,Why can't he jump ? 0 Answers

Making a bubble level (not a game but work tool) 1 Answer

Multiple jump C# Script. 0 Answers

Adding MidAir Movement to Default Third Person Character 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