Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Gohst002 · Jun 03, 2017 at 11:53 AM · gravityfps controllerfpstutorialclimb

character climb

I looked at a tutorial on how to make a basic FPS controller and coud not figure out how to make the character climb a wall when he jumps against it and it has the tag JumpBoost. using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayerMovement : MonoBehaviour {

public float speed = 2f;

 public float sens = 2f;

 public float jumpForce = 4f    ;

 public float gravity;

 public float climbForce;

 public Rigidbody rB;

 private Collider other;

 CharacterController player;

 public GameObject eyes;

 float moveFB, moveLR, rotX, rotY, verticalVelocity;
 private bool hasJumped, isCrouched;

 // Use this for initialization
 void Start () {
     Cursor.visible = false;
     Cursor.lockState = CursorLockMode.Locked;
     player = GetComponent<CharacterController> ();
     other = GetComponent<Collider> ();
 }
 
 // Update is called once per frame
 void Update () {
     Movement ();
     if (Input.GetButtonDown ("Jump")) 
     {
         hasJumped = true;        
     }
     ApplyGravity ();

     if (Input.GetButtonDown ("Crouch")) 
     {
         if (isCrouched == false) 
         {
             isCrouched = true;
             player.height = player.height / 2;    
         }
     }
     if (Input.GetButtonUp ("Crouch"))
     {
         if (isCrouched == true)
         {
             isCrouched = false;
             player.height = player.height * 2;    
         }
     }
 }

 public void Movement()
 {
     moveFB = Input.GetAxis ("Vertical") * speed;
     moveLR = Input.GetAxis("Horizontal") * speed;

     rotX = Input.GetAxis ("Mouse X") * sens;
     rotY = Input.GetAxis ("Mouse Y") * sens;


     Vector3 movement = new Vector3 (moveLR,verticalVelocity,moveFB);
     Vector3 climb = new Vector3 (0, climbForce, 0);
     transform.Rotate (0,rotX,0);
     movement = transform.rotation * movement;
     climb = transform.position.y * climb;
     player.Move (movement * Time.deltaTime);
     player.Move (climb * Time.deltaTime);
     eyes.transform.Rotate (-rotY, 0, 0);

     if (Input.GetKeyDown (KeyCode.LeftShift)) 
     {
         speed = 7f;
     }
     if (Input.GetKeyUp (KeyCode.LeftShift)) 
     {
         speed = 4f;
     }
 }


 private void ApplyGravity()
 {
     if (player.isGrounded == true) 
     {
         if (hasJumped == false) 
         {
             verticalVelocity = Physics.gravity.y * gravity;
         } 
         else 
         {
             verticalVelocity = jumpForce;
         }
     } 
     else 
     {
         verticalVelocity += Physics.gravity.y * gravity * Time.deltaTime;
         verticalVelocity = Mathf.Clamp (verticalVelocity, -50f, jumpForce);
         hasJumped = false;
     }
     if (player.isGrounded == false) 
     {
         if (other.GetComponent<Collider> ().tag == "JumpBoost" && hasJumped == true) 
         {
             Vector3 climb = new Vector3 (0,climbForce,0);
         }
     }
 }

}

I tried making a climb Vector3 but my player always bugs out and gets hit by gravity when he hits the object.

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

0 Replies

· Add your reply
  • Sort: 

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

68 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

Related Questions

Changing gravity at the click of a button... 5 Answers

simple roll a ball game - ball slips threw ground 1 Answer

Spheres change form on collision 0 Answers

How to make GameObject fall with the same gravity while using AddForce() 1 Answer

[Kudan AR] (Markerless) Augmented Reality and Rigidbodies 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