Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Liraseth · Oct 06, 2019 at 07:46 AM · physicsjumpscriptingbasicsplayer movementwall jump

Wall Jump Scripting Help

alt textHi, Im trying to make a simple fast paced 3D plat former to learn the basics of unity. I wish to implement a wall jump that is relative to the surface the player is standing on so i dont have to create many diffrent implementations of what the player is standing on. This is my script so far...

 using System.Collections;
 
 using System.Collections.Generic;
 
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour
 
 {
 
     public float speed;
     public float jump = 20f;
     private Rigidbody rb;
     float timer = 0.0f;
     bool isGrounded = true;
    
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
  
 
 
     private void Update()
     {
         bool player_jump = Input.GetButtonDown("Jump");
 
         if (player_jump && isGrounded)
         {
             rb.AddForce(Vector3.up * jump);
         }
     }
 
 
 
 
     void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.CompareTag("Ground"))
         {
             isGrounded = true;            
         }
         if (collision.gameObject.CompareTag("Wall"))
         {
             isGrounded = true;
         }
 
     }
 
 
 
 
     void OnCollisionExit(Collision collision)
     {
         if (collision.gameObject.CompareTag("Ground"))
         {
             isGrounded = false;
         }
         if (collision.gameObject.CompareTag("Wall"))
         {
             isGrounded = false;
         }
     }




 void FixedUpdate()
 {
     float moveHorizontal = Input.GetAxis("Horizontal");
     float moveVertical = Input.GetAxis("Vertical");

     Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

     rb.AddForce(movement * speed);
 }

}

So, My player is a ball and i wish to have it able to wall jump off of a wall. For now it jumps only up and i want to be able to grate a jump that applies a force off the wall. Like in Mario. So how do i create a wall jump that is relative to the surface that the player is standing on?

2019-10-06-16-22-39-3.gif (352.7 kB)
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 tormentoarmagedoom · Oct 06, 2019 at 11:46 AM 0
Share

Hello.

Ok, nice project, nice script but... Whats the question then? Can you make a santence with your question ? :D

avatar image Liraseth tormentoarmagedoom · Oct 06, 2019 at 02:19 PM 0
Share

$$anonymous$$y player is a ball and i wish to have it able to wall jump off of a wall. For now it jumps only up and i want to be able to grate a jump that applies a force off the wall. Like in $$anonymous$$ario. So how do i create a wall jump that is relative to the surface that the player is standing on?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by unity_2_3_VXKGFGtKtg · Oct 06, 2019 at 07:31 PM

hello there, i was asking about this from 2 days too no one replied, now what i did in my project that i used OnCollisionEnter and add two force one in the direction of wall normal and one in the upward direction it worked, but it has some bugs too since no one replying about wall jumping i thought i should tell you what solution in found

NOTE IT IS NOT PREFECT HAS BUGS

  void OnCollisionEnter(Collision collision)
         {
             foreach (ContactPoint contact in collision.contacts)
             {
                 if (!IsGrounded && contact.normal.y < 0.1f)
                 {
                     Debug.DrawRay(contact.point, contact.normal, Color.yellow, 5f);
                     if (walljump == true)
                     {
                         characterControl.RIGIDBODY.AddForce(contact.normal * 6f, ForceMode.Impulse);
                         characterControl.RIGIDBODY.AddForce(Vector3.up * 3f, ForceMode.Impulse);
                     }
                 }
             }
         }
Comment
Add comment · Show 5 · 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 Liraseth · Oct 06, 2019 at 09:41 PM 0
Share

I do get this error code from it... do you know how to fix it?!

PlayerController.cs(92,25): error CS0103: The name 'CharacterColtrol' does not exist in the current context

avatar image unity_2_3_VXKGFGtKtg Liraseth · Oct 07, 2019 at 04:32 AM 0
Share

CharacterControl is script in my project from which i am using property to access rigidbody , in your case it'll be rb.AddForce

avatar image Liraseth unity_2_3_VXKGFGtKtg · Oct 08, 2019 at 07:22 AM 0
Share

Could you post your entire script so I can see what I can change in $$anonymous$$e?! Because it is not working yet.

Show more comments
avatar image
0

Answer by Blueshrimps · Mar 16 at 02:10 PM

Hello Liraseth! I was having similar problems with wall jumping. I at first tried using raycasting to determine the hit point, but when that didn't work, I reverted to a much simpler method. This is for character controllers, though.

private void OnControllerColliderHit(ControllerColliderHit hit) { if(!controller.isGrounded && controller.collisionFlags == CollisionFlags.Sides && Input.GetKey(KeyCode.Space)) { (your move vector).y = jumpForce; transform.rotation = Quaternion.Euler(0f, transform.rotation.eulerAngles.y + 180f, 0f); float getYRotation = transform.rotation.eulerAngles.y; transform.position += transform.forward Time.deltaTime (your move speed); lockMove = true; }

This method makes the player turn around 180 degrees, so it works even if you hit the wall at a diagonal angle. for the "lock move" bool, only allow your player to rotate if lock move is false, and then set it to false when grounded.

The way this works it that when the player does a wall jump, they will flip around and stay in that direction, and trying to move the player back toward the wall will just move them further away. if you need to get the player's y rotation, the float variable in there can track it. I really hope this works for you and is compatible with your script!

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

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

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

Related Questions

R-Type style movement 0 Answers

How could I add ui images to an instantiated prefab by photon ?? 0 Answers

Sphere get stuck in floor and fails to jump? 1 Answer

Make a ball jump on plane collision 1 Answer

5.4 broke rigidbody.addForce? 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