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 /
avatar image
0
Question by Henriick · Dec 05, 2015 at 06:18 PM · velocityjumping

ThirdPersonCharacter script blocks trampoline jump

(I'm brazillian, sorry for the english) My trampoline script:

using UnityEngine; using System.Collections;

public class Trampoline : MonoBehaviour {

 Animator anim;
 [System.NonSerialized]public bool onTop;

 GameObject bouncer;

 public Vector3 JumpPower;

 void Start () {
     anim = GetComponent<Animator>();
 }
 
 // Update is called once per frame
 void Update () {

 }

 void OnCollisionStay(Collision other)
 {
     if(onTop)
     {
         anim.SetBool("isStepped", true);
         bouncer = other.gameObject;
     }
 }

 void OnTriggerEnter()
 {
     onTop = true;
 }

 void OnTriggerExit()
 {
     onTop = false;
     anim.SetBool("isStepped", false);
 }

 void Jump()
 {
     bouncer.GetComponent<Rigidbody>().velocity = JumpPower;
 }

}

others objects jump fine, and if I disable just one of the two ThirdPersonCharacter scripts of my character work too, I try many things but I can't make it work, if you want to see the a little bit of ThirdPersonCharacter script, I think this is caused by velocity var(Vector3) and the manipulation of useGravity Comand, thank you for the patience:

     void Update()
     {
         if(onGround)
         {
             doubleJumped = false;
         }
    public void Move(float h, float v, bool crouch, bool jump, Vector3 lookPos, Vector3 move)
     {
         if (h != 0f || v != 0f) 
         {
             rotate(v,h);
             
             animator.SetFloat ("Forward", 1f, 0.1f, Time.deltaTime);
         }
         else {
             animator.SetFloat ("Forward", 0f, 0.1f, Time.deltaTime);
         }
         //if (move.magnitude > 1) move.Normalize();

         // transfer input parameters to member variables.
         this.moveInput = move;
         this.crouchInput = crouch;
         this.jumpInput = jump;
         this.currentLookPos = lookPos;

         // grab current velocity, we will be changing it.
         velocity = GetComponent<Rigidbody>().velocity;

         ConvertMoveInput(); // converts the relative move vector into local turn & fwd values

// TurnTowardsCameraForward(); // makes the character face the way the camera is looking

         PreventStandingInLowHeadroom(); // so the character's head doesn't penetrate a low ceiling

         ScaleCapsuleForCrouching(); // so you can fit under low areas when crouching

// ApplyExtraTurnRotation(); // this is in addition to root rotation in the animations

         GroundCheck(); // detect and stick to ground

         SetFriction(); // use low or high friction values depending on the current state

         // control and velocity handling is different when grounded and airborne:
         if (onGround)
         {
             HandleGroundedVelocities();
         }
         else
         {
             HandleAirborneVelocities();
         }

         UpdateAnimator(); // send input and other state parameters to the animator

         // reassign velocity, since it will have been modified by the above functions.
         GetComponent<Rigidbody>().velocity = velocity;


     }

     private void GroundCheck()
     {
         Ray ray = new Ray(transform.position + Vector3.up*.1f, -Vector3.up);
         RaycastHit[] hits = Physics.RaycastAll(ray, .5f,groundCheckMask);
         System.Array.Sort(hits, rayHitComparer);

         if (velocity.y < jumpPower*.5f)
         {
             onGround = false;
             GetComponent<Rigidbody>().useGravity = true;
             foreach (var hit in hits)
             {
                 // check whether we hit a non-trigger collider (and not the character itself)
                 if (!hit.collider.isTrigger)
                 {
                     // this counts as being on ground.

                     // stick to surface - helps character stick to ground - specially when running down slopes
                     if (velocity.y <= 0)
                     {
                         GetComponent<Rigidbody>().position = Vector3.MoveTowards(GetComponent<Rigidbody>().position, hit.point,
                                                                  Time.deltaTime*advancedSettings.groundStickyEffect);
                     }

                     onGround = true;
                     GetComponent<Rigidbody>().useGravity = false;
                     break;
                 }
             }
         }

         // remember when we were last in air, for jump delay
         if (!onGround) lastAirTime = Time.time;

     }

    private void HandleGroundedVelocities()
     {
         velocity.y = 0;

         if (moveInput.magnitude == 0)
         {
             // when not moving this prevents sliding on slopes:
             velocity.x = 0;
             velocity.z = 0;
         }
         // check whether conditions are right to allow a jump:
         bool animationGrounded = animator.GetCurrentAnimatorStateInfo(0).IsName("Grounded");
         bool okToRepeatJump = Time.time > lastAirTime + advancedSettings.jumpRepeatDelayTime;

         if (jumpInput && !crouchInput && /*okToRepeatJump &&*/ animationGrounded)
         {
             // jump!
             onGround = false;
             velocity = moveInput*airSpeed;
             velocity.y = jumpPower;
             jumpParticle.Emit(3);
         }
     }

     private void HandleAirborneVelocities()
     {
         // we allow some movement in air, but it's very different to when on ground
         // (typically allowing a small change in trajectory)
         Vector3 airMove = new Vector3(moveInput.x*airSpeed, velocity.y, moveInput.z*airSpeed);
         velocity = Vector3.Lerp(velocity, airMove, Time.deltaTime*airControl);
         GetComponent<Rigidbody>().useGravity = true;

         // apply extra gravity from multiplier:
         Vector3 extraGravityForce = (Physics.gravity*gravityMultiplier) - Physics.gravity;
         GetComponent<Rigidbody>().AddForce(extraGravityForce);

         if(jumpInput && !doubleJumped)
         {
             velocity.y = jumpPower;
             doubleJumped = true;
             animator.SetTrigger("DoubleJump");
             jumpParticle.Emit(3);
         }

     }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rigidbody flies up instead of just jumping. 1 Answer

Jumping a specific height using Velocity & Gravity 1 Answer

Why does Gravity (Physics2D) produce different results for AddForce() versus velocity in player sprite? 2 Answers

Drop in performance when checking velocity of rigidbody.,Performance drop when checking velocity of rigidbody. 1 Answer

Why is enemy jumping at different speed even though the velocity is the same? 0 Answers


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