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 /
avatar image
0
Question by mike670 · Jun 17, 2011 at 04:48 PM · jumpballwall

Wall jumping problem

Hey guys!

Im having an issue I hope you can help me out with, currently I'm making a game that has a ball that you can control and jump. The problem is that when I jump on a wall it glides all the way up!

I tried using tags for the ground and such but that does not help as there will be obstacles you must jump over so you can still glide over those.

I also tried to use a character controller, but this just broke the entire thing and it just floats there?

The object I'm trying to control has the attached script, a rigidbody and sphere collider

Thanks for taking a look at my problem!

-mike

 var power = 50.0;  //speed of the ball
 var drag = 2.0; //how much to slow down when not controlling
 private var grounded = false; 
 var once = 0;  //var to set the direction of ball jump only once
 var jumpForce;  //var to set how high the ball should bounce
 
 function FixedUpdate () {
  // Only apply forces if the ball is on the floor
  if (grounded) {
   // Calculate the direction in which we want to roll the ball
   // * It is relative to the camera
   // * we remove the y component because we really want to apply forces only on the 2D plane
   var forward = Camera.main.transform.TransformDirection(Vector3.forward);
   forward.y = 0;
   forward = forward.normalized;
 
   // Scale the force by the users input and apply it to the rigidbody
   var forwardForce = forward * Input.GetAxis("Vertical") * power;
   rigidbody.AddForce(forwardForce);
   
   // Calculate the direction in which we want to roll the ball
   // * It is relative to the camera
   // * we remove the y component because we really want to apply forces only on the 2D plane
   var right = Camera.main.transform.TransformDirection(Vector3.right);
   right.y = 0;
   right = right.normalized;
 
   // Scale the force by the users input and apply it to the rigidbody
   var rightForce = right * Input.GetAxis("Horizontal") * power;
   rigidbody.AddForce(rightForce);
   
   //this sets the direction of force to be applied when jumping
   if (once==0){
         jumpForce =  rigidbody.transform.TransformDirection(Vector3.up);
         once = 1;
     }
     
     //jump
   if (Input.GetAxis("Jump")&&once==1){
         rigidbody.AddForce(jumpForce*35);
     }
     
   // Apply drag only if the user is not pressing any keys
   if (Mathf.Approximately (Input.GetAxis("Horizontal"), 0) && Mathf.Approximately(Input.GetAxis("Vertical"), 0))
    rigidbody.drag = drag;
   else
    rigidbody.drag = 0; 
  }
  // Every frame set grounded to false. OnCollisionStay will enable it again if
  // the rigidbody collides with anything
  grounded = false;
 }
 
  function OnCollisionStay(collision:Collision) {
 if(collision.gameObject.tag=="ground") {
  grounded = true;
  }
 }
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 CarlLawl · Jun 18, 2011 at 01:18 PM 0
Share

Just a quick side note for your code, ins$$anonymous$$d of changing grounded every frame, would it not just be easier to set ground to false using oncollisionexit or when you jump?

avatar image mike670 · Jun 18, 2011 at 04:52 PM 0
Share

very true thanks!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Johan 4 · Jun 18, 2011 at 01:37 PM

Sadly I don't have the code right now, but I solved this by shooting a ray and checking surface angle and then performing stuff according to what angle it got.

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 mike670 · Jun 18, 2011 at 04:52 PM 0
Share

ah, yes this would work thanks for the tip

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Ball jump on collision problem 1 Answer

Creating A wall Jump 0 Answers

How Can I Make My Character Double Jump and Wall Jump? 1 Answer

Simple wall jump? 2 Answers

collision with wall so player dies 1 Answer


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