• 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?

1 Reply

· 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 mine?! Because it is not working yet.

Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

194 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

Related Questions

I need help with a movement script 1 Answer

Collision between CircleCollider2D and BoxCollider2D causing physics problems 0 Answers

Raycast not interacting! 0 Answers

Trouble with spring platform 0 Answers

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