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 N1warhead · Oct 03, 2014 at 01:07 AM · jumpingcollisions

Ground and Object Jumping problem

Hey guys, Here is my problem. My Jumping works fine, however, lets say I jump when I am literally against the wall, as the photo shows. Like literally facing the wall and against it and press jump. Well it's disabling my canJump Bool and won't reactivate unless I climb up and object and fall off it and hit the ground again. No matter what order I put it in.

Is there something I am missing here?

I'll post both the player code and the Object Detection code.

PLAYER CODE.

 using UnityEngine;
 using System.Collections;
 // REQUIRED COMPONENTS TO WORK!
 [RequireComponent(typeof (Animator))]
 
 public class Controller : MonoBehaviour {
 
     private CapsuleCollider col; // This is the Collider for Player.
     private Animator anim;    // This is the Animator for Player.
     public float Speed = 5.0f;
     public float TurnSpeed = 5.0f;
     public float jumpHeight = 10.0f;
     public bool canJump;
     public bool grounded;
     public bool ObjDetected = false;
 
     // Use this for initialization
     void Start () {
         anim = gameObject.GetComponent<Animator>();                      
         grounded = true;
     }
     
     // Update is called once per frame
     void Update () {
         //if (grounded) {
         if (Input.GetKey (KeyCode.W)) {
                 transform.Translate (Vector3.forward * Speed * Time.deltaTime);
                 anim.SetFloat ("Speed", 1f);
             } else {
                 anim.SetFloat ("Speed", 0f);
             }
         if (Input.GetKey (KeyCode.S)){
                 transform.Translate (Vector3.back * Speed * Time.deltaTime);
                 anim.SetFloat ("WalkBack", -1f);
             } else {
                 anim.SetFloat ("WalkBack", 0f);
             }
         if(Input.GetKey (KeyCode.A)){
                 transform.Rotate (0,-5,0);
             }
         if(Input.GetKey (KeyCode.D)){
                 transform.Rotate (0,5,0);
             }
         if (ObjDetected) {
             transform.Translate(Vector3.back * 5 * Time.deltaTime);
                 }
     //}
 }
     void FixedUpdate(){
 
                 if (Input.GetKeyDown (KeyCode.Space) && canJump == true) {
                         if (canJump) {
 
                                 transform.rigidbody.AddForce (Vector3.up * jumpHeight);
                                 Physics.gravity = new Vector3 (0, -20, 0);
                                 canJump = false;
 
                         } else {
                                 canJump = true;
                         }
                 }
         }
     void OnCollisionEnter(Collision col){
          if (col.gameObject.tag == "Map") {
             canJump = true;
                 }
         }
 }
 

OBJECT DETECTION CODE (IT'S A BOX TRIGGER)

 using UnityEngine;
 using System.Collections;
 
 public class ObjectDetection : MonoBehaviour {
 
     public Controller controller;
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnTriggerEnter(Collider col){
         if (col.gameObject.tag == "LvlObject" && Input.GetKey (KeyCode.Space)) {
             Debug.Log ("Object Detected");
             controller.ObjDetected = true;
             }
         }
     void OnTriggerExit(Collider col){
         if (col.gameObject.tag == "LvlObject") {
             Debug.Log ("Object no longer detected");
             controller.ObjDetected = false;
     }
     }
 }
 

Can you please help me figure out why this happens or at least guide me to the right path? I would do a raycast, but it got confusing with how to exactly implement it, as I've never really used Rays before.

alt text

concept.jpg (36.3 kB)
Comment
Add comment · Show 1
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 N1warhead · Oct 03, 2014 at 01:19 AM 0
Share

EDIT - Figured I'd add as a comment as it would be easier to read.

I forgot to mention I pretty much created a little useless hack around to make it kind of work.

I had it just reactivate the canJump bool when I left the trigger. However that's not exactly what I am looking for.. I'm wanting to still jump when I hit the ground regardless, not when I leave the trigger.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by sevensixtytwo · Oct 03, 2014 at 02:39 AM

Try using OnTriggerStay to set your canJump bool to true as long as it's inside the trigger and then setting the bool to false at the end of every frame using LateUpdate.

This is how, IIRC, the RigidbodyFPSWalker script did it in the unity wiki.

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 N1warhead · Oct 03, 2014 at 02:43 AM 0
Share

Thank you!

I just did what you put and it worked!

Thank you very much for your help!

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

27 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

Related Questions

Graceful 2D collision enabling/disabling for topdown jumping 1 Answer

Character Movement and Jumping Script? 4 Answers

Jumping boolean check 2 Answers

Interpolation with jumping - Acting Weird. 1 Answer

OnCollisionEnter2D and OnCollisionExit2D 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