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 seanybaby2 · May 22, 2013 at 05:41 AM · javascriptwallwall jumpmovedirection

Trying to get my wall Jump to Work

Hey Guys. I'm trying to get my wall jump to work. Right now my character is only jumping straight into the air when he hits the wall. I want him to bounce the other direction he was moving when he jumps onto the wall? What kind of script would I use to do this? I've been trying to figure it out and cant. Take a look at the code I have so far.

 private var canWallJump : boolean=false;
 private var canWallJumpTime : float = 0;
 
 var speed : float = 10.0;
 var jumpSpeed : float = 10.0;
 var gravity : float = 20.0;
 
 
     
     function Update () {        
         
         var fwd = transform.TransformDirection (Vector3.forward);
         var controller : CharacterController = GetComponent(CharacterController);
        
        
            if (controller.isGrounded == false){
                 moveDirection = Vector3(Input.GetAxis("Vertical"),0);
                 moveDirection = transform.TransformDirection(moveDirection);
                 moveDirection *= speed;
                 canWallJump = true;
                 canWallJumpTime = Time.time;
         //        canWallJumpDir = Vector3.Scale(Vector3(-1,0,-1), lastDirection);
                 if(Time.time - canWallJumpTime > .25) canWallJump = false;
                 if(Physics.Raycast(transform.position, fwd, 1 && Input.GetButton("Jump") && canWallJump)) {
                     print("There is something in front of the object!");
                     moveDirection.y = jumpSpeed;
                
             }
         else{
             print ("We are grounded");
             }
         }
     // apply gravity
     moveDirection.y -= gravity * Time.deltaTime;
     
     // Move The controller
     controller.Move(moveDirection * Time.deltaTime);
     
     //last direction before wall contact
 //    lastDirection = movement;
   }
     
 @script RequireComponent (CharacterMotor)
Comment
Add comment · Show 2
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 MD_Reptile · May 22, 2013 at 06:41 AM 0
Share

@seanybaby2 I think I see, but I am sorta wondering what is actually happening when you use this code. You say that he jumps straight up when it happens, so like its making it as far as detecting the wall and then jumping straight up?

If its happening no problem that way, then it should be easy to just use the hit normal from a raycast onto the collided object (wall) and sort of lerp your character around real quick to that direction and continue forward movement.

Also I see you have moveDirection.y being set when you try to do this, but maybe ins$$anonymous$$d you need to be taking the normal of the raycast that just hit, and saying "rotate my character sorta fast to face opposite of this hit" sort of...

and ummm... the Time.time - camWallJumpTime part didnt make sense to me... was that supposed to be more like timeSinceFirstJumpingOffTheGround - timeUntilWereAllowedToWallJump?

avatar image seanybaby2 · May 23, 2013 at 03:01 AM 0
Share

Yes that's right $$anonymous$$d_Reptile. I am hitting the wall, detecting it and jumping straight up.

Okay I haven't done a hit normal before so that's probably my problem ill look into that.

As for the last part maybe I am doing it wrong. I'm trying to make it so the player only has about a 1/4 second to react to wall jump after they hit the wall.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tomer-Barkan · May 22, 2013 at 07:11 AM

There are some problems that I find with your code, hopefully one of them will fix your issue:

            moveDirection = Vector3(Input.GetAxis("Vertical"),0);
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= speed;

In this code you're setting moveDirection to be similar to the input, but then you immediately override it with the forward direction, so the input is basically ignored.

 if(Physics.Raycast(transform.position, fwd, 1 && Input.GetButton("Jump") && canWallJump)) {

Here it seems like you forgot one parenthesis. You are && the distance (1) with the input stuff. Try this instead:

 if(Physics.Raycast(transform.position, fwd, 1) && Input.GetButton("Jump") && canWallJump) {
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 MD_Reptile · May 22, 2013 at 07:23 AM 0
Share

I saw the first part, but thought he wanted to constantly move forward while airborne. The first line is useless, because the line below does cancel it out though doesn't it.

Good eye tbkn

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

16 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

Related Questions

get input slowly. 2 Answers

3d wall jumping with charter controller 1 Answer

Jumping away from a wall 1 Answer

Where can I start to learn more about coding? 2 Answers

How do i learn C# or UnityScript as a teen? 6 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