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 temen · Mar 15, 2017 at 03:00 PM · jumpingloopframes

Frame Base Jump Loop

I have a problem with my frame based jumping loop. It does the check every frame to see if the vertical axis is greater than 33%. Then it checks if the axis is being held down. It then executes the Jumping function which is supposed to keep the frame on which the jump is activate and then see is the current frame is equal to the stored frame plus 4. If that is the case then add to the vertical velocity variable which is later added in LateUpdate().

My problem is, is that check[1] is true on every frame so it sets my current frame to the newest one every time so the player never jumps. What I need is for check[1] to be done once so that it will store the correct frame and then jump 4 frames later.

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class WalkingController : Controller {
 
     Vector3 walkVel;
     float adjVertVel;
     int jumpPressFrm;
     float jumpVel = 0f;
 
     // 0 is for isDashing(), 1 is for checkJumping,
     int[] curFrm = new int[64]; 
     bool[] check = new bool[64];
 
     public override void ReadInput(InputData data)
     {
         walkVel = Vector3.zero;
         adjVertVel = 0f;
 
         //Debug.Log("Frame: " + Time.frameCount);
         checkDashing(data);
         checkJumpCrouch(data);
 
     }
     void LateUpdate()
     {
         rb.velocity = new Vector3(walkVel.x, rb.velocity.y + adjVertVel, walkVel.z);
         walkVel = Vector3.zero;
     }
 
     void checkDashing(InputData data)
     {
         
 
         if (data.axes[1] != 0f && isDashing(data))
         {
             walkVel += Vector3.right * data.axes[1] * 3;
 
         }
         else if (data.axes[1] != 0f && !isDashing(data))
         {
             walkVel += Vector3.right * data.axes[1];
         }
 
 
         if (!isDashing(data) && data.axes[1] == 0f)
         {
             check[0] = true;
         }
     }
 
     bool isDashing(InputData data)
     {
         while(check[0])
         {
             curFrm[0] = Time.frameCount;
             check[0] = false;
         }
 
         if (Time.frameCount >= curFrm[0] + 12 || data.axes[1] == 0f)
         {
             return false;
         }
         return true;
     }
 
 
     //JumpCrouch is the state of the player before they enter jump
     void checkJumpCrouch(InputData data)
     {
         if (data.axes[0] >= (1f / 3f) || data.buttons[2] == true)
         {
             if (jumpPressFrm == 0)
             {
                 check[1] = true;
                 checkJumping(data); 
             }
             jumpPressFrm += Time.frameCount;
         }
         else { jumpPressFrm = 0;}
     }
     //My problem is, is that check[1] is true on every frame so it sets my current frame to the 
     //newest one every time so the player never jumps. What I need is for check to be done once
     //so that it will store the correct frame and then jump 4 frames later.
     void checkJumping(InputData data)
     {
              
         while (check[1])
         {
             curFrm[1] = Time.frameCount;
             jumpVel = 10f;
             check[1] = false;
         }
         if (Time.frameCount >= curFrm[1] + 4 && Grounded())
         {
             
             adjVertVel += jumpVel;
             jumpVel = 0f;
         }       
     }
 
     bool Grounded()
     {
         
         return Physics.Raycast
             (transform.position, Vector3.down, coll.bounds.extents.y + 1f);
     }
 
 }
 
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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Breaking out of the right loop 1 Answer

Loop in coroutine stops after going halfway 2 Answers

Round Loop Problem?... 1 Answer

3D Side-Scrolling shooter looping background 0 Answers

How do I delete objects in an animation in a certain order? 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