Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 abdelrahmanyoussry509 · Aug 04, 2020 at 11:38 AM · scripting problemvector3jumpinghow to

How do i make my player jump from an angle? (Wallrun Jump)

hi i will get to the point , i want my player while he is running on the wall ,when i press space he jumps from the wall he is running on at an 45 degree angle so he will be able to reach the other wall oppsite to the other wall

i made the wall run and jumping but when he jumps he jumps up not at 45 degree angle i want

if you know how to fix it please explain it to me cuse i am new and dumb Thank you :P

(The Line that is the Problem is from line 225 to 230)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Motion : MonoBehaviour
 {
     public float speed;
     private Rigidbody rig;
     public float sprintmodifire;
     public Camera PlayerCam;
 
 
     private float remove;
 
 
     public Transform groundchek;
     public LayerMask groundmask;
     private float t_adjustedSpeed;
 
     public float jumpforce;
     private float BaseFOV;
     private float FOVmodifre = 1.2f;
 
     //bobling
     public Transform WeaponParent;
     private Vector3 WeaponParentOrgin;
     private float MovementCounter;//counts the secounds you are moving
     private float IdelCounter;
     private Vector3 WeaponBobTarget;
 
 
     public bool isRuningLEFT = false;
     public bool isRuningRigh = false;
     private RaycastHit HitLEF;
     private RaycastHit HitRIG;
     private float jumpCount = 0;
 
 
     private bool IsGrapPush= false;
     public GameObject Explostion;
     
 
 
     void Start()
     {
         rig = GetComponent<Rigidbody>();
         BaseFOV = PlayerCam.fieldOfView;
 
         remove = 1;
         
         WeaponParentOrgin = WeaponParent.localPosition;
         
         
     }
 
     public IEnumerator GrapplePush()
     {
         rig.AddRelativeForce((Vector3.forward * t_adjustedSpeed / 7));
         yield return new WaitForSeconds(1f);
         FindObjectOfType<GrapplingGunScript>().isGrapling = false;
          
 
     }
     private void Update()
     {
         //axis
         float t_Hmove = Input.GetAxis("Horizontal");
         float t_Vmove = Input.GetAxis("Vertical");
         //controls
         bool spirnt = Input.GetKey(KeyCode.LeftShift);
         bool jump = Input.GetKey(KeyCode.Space);
 
 
         Vector3 t_direction = new Vector3(t_Hmove, 0, t_Vmove);
         t_direction.Normalize();
 
 
         //Headbobling
         if(t_Hmove == 0 && t_Vmove == 0)
         {
             Headbob(IdelCounter,0.025f,0.025f);
             IdelCounter += Time.deltaTime ;
         }else if (spirnt)
         {
             Headbob(MovementCounter, 0.1f, 0.075f);
             MovementCounter += Time.deltaTime * 5;
 
         }
         else
         {
             Headbob(MovementCounter, 0.05f, 0.05f);
             MovementCounter += Time.deltaTime *3;
             
         }
         WeaponParent.localPosition = Vector3.Lerp(WeaponParent.localPosition, WeaponBobTarget, Time.deltaTime * 8f);
 
       
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
 
         var grappler = FindObjectOfType<GrapplingGunScript>();
          bool isGorunded;
         isGorunded = Physics.Raycast(groundchek.position, Vector3.down, 0.1f, groundmask);
         //Axis and motion
         float t_Hmove = Input.GetAxis("Horizontal");
         float t_Vmove = Input.GetAxis("Vertical");
         //we save them both in a vector 3
         Vector3 t_direction = new Vector3(  t_Hmove,0, t_Vmove);
         // when we press w and d at same time we add 1from w on 1 from d so it makes player go faster so we nomlize (keep it 1)
         t_direction.Normalize();
         
         //Controls
         bool spirnt = Input.GetKey(KeyCode.LeftShift);
         bool jump = Input.GetKey(KeyCode.Space);
         
 
         //MOTION AND SPRINT
 
         bool isjumping = jump;
         bool isSprinting = spirnt && t_Vmove >0 && !isjumping && isGorunded ||isRuningLEFT ||isRuningRigh || IsGrapPush;
 
         if (isjumping && isGorunded )
         {
             rig.AddForce( Vector3.up * jumpforce);
         }
          t_adjustedSpeed = speed;
 
 
         //GRAPPLE
         IEnumerator GrapplePush()
         {
             rig.AddRelativeForce((Vector3.forward * t_adjustedSpeed / 12));
             yield return new WaitForSeconds(0.7f);
             FindObjectOfType<GrapplingGunScript>().isGrapling = false;
             IsGrapPush = true;
             yield return new WaitForSeconds(1f);
             IsGrapPush = false;
 
         }
 
 
         if (isSprinting)
         {
             t_adjustedSpeed = sprintmodifire * t_adjustedSpeed;
             
         }
         if (grappler == null || !grappler.isGrapling)
         {
                 Vector3 TargetVelocity = transform.TransformDirection(t_direction) * t_adjustedSpeed * Time.deltaTime;
                 TargetVelocity.y = rig.velocity.y;
                 rig.velocity = TargetVelocity;
             
         }
         else if(grappler != null && grappler.isGrapling)
         {
 
             StartCoroutine(GrapplePush());
             
 
 
 
         }
 
 
         if (isSprinting)
         {
             PlayerCam.fieldOfView = Mathf.Lerp(PlayerCam.fieldOfView,BaseFOV *FOVmodifre,Time.deltaTime*8f);
         }
         else
         {
             PlayerCam.fieldOfView = Mathf.Lerp(PlayerCam.fieldOfView, BaseFOV , Time.deltaTime * 8f);
         }
 
         //Wallrun code
         if (isGorunded)
         {
             jumpCount = 0f;
         }
         
         if (remove == 1 )
         {
             if (Physics.Raycast(transform.position, transform.right, out HitRIG, 1))
             {
                 if (HitRIG.transform.tag == "Wall")
                 {
                     isRuningLEFT = false;
                     isRuningRigh = true;
                     jumpCount += 1;
                     rig.useGravity = false;
                     rig.AddForce(100, 0, 0);
                    
 
 
                 }
 
             }
             else if (Physics.Raycast(transform.position, -transform.right, out HitLEF, 1))
             {
                 if (HitLEF.transform.tag == "Wall")
                 {
                     isRuningLEFT = true;
                     isRuningRigh = false;
                     jumpCount += 1;
                     rig.useGravity = false;
                     rig.AddForce(100,0,0);
 
 
 
                 }
 
 
 
             }
             
             else
             {
                 isRuningLEFT = false;
                 isRuningRigh = false;
                  rig.useGravity = true;
                 
             }
             
         }
         if(isRuningLEFT && Input.GetKeyDown(KeyCode.Space) || isRuningRigh && Input.GetKeyDown(KeyCode.Space))
         {
             rig.AddForce(Vector3.up  * 20, ForceMode.Impulse);
             print("is jumping");
             
         }
         
         
        
         
     }
 
     void Headbob(float p_z,float X,float Y)
     {
         WeaponBobTarget = WeaponParentOrgin+ new Vector3(Mathf.Cos(p_z ) * X, Mathf.Sin(p_z * 2) * Y, 0);
     }
 
 
 }
 

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by davidcox70 · Aug 04, 2020 at 01:13 PM

Try adding some left or right direction into your addForce:

     if(isRuningLEFT && Input.GetKeyDown(KeyCode.Space))
         {
          rig.AddForce((Vector3.up+Vector3.left)  * 20, ForceMode.Impulse);
          print("is jumping left");
         }
         
  if (isRuningRigh && Input.GetKeyDown(KeyCode.Space))
        {
               rig.AddForce((Vector3.up+Vector3.right)  * 20, ForceMode.Impulse);
               print("is jumping right");
                      
         }
         
         
     
     


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

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

Can someone help me with the jumping in this Player Controller script? 1 Answer

Why isn't my teleport on collision script working? 0 Answers

lock turret rotation to local Y 2 Answers

Why isn't my move on collision script working? 0 Answers

Get Y Rotation Between Two Vector3 Points 2 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