Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 SanderN · Mar 13, 2015 at 01:12 AM · javascriptrigidbodysmoothsidescrollersliding

Rigidbody controller slide up walls?(Sidescroller)

Hello! I need some help with rigidbody sidescroller script!

I want to make a really 'smooth' sidescroller controller based on rigidbody. By 'smooth' I mean a controller that relies a lot on physics and can be easily be influenced by other objects in the scene.

Now the problem I'm having at the moment is that I don't know how to make it so that my character would slide on walls when I jump into them. At the moment when I jump into a wall and I keep pressing horizontal movement my character just gets 'stuck' and doesn't move and when I release horizontal controls it takes about half a seconds before the character starts falling.

So what I want to do is that when I jump into a wall the character wouldn't just 'stop' but would keep sliding on the wall up or down depending on the angel it hits the wall. I guess the best example would be something similar to Super Meat Boy but without locking character to the wall.

Here's the script I managed to put together:

 #pragma strict
 var MoveSpeed : float = 1;
 var JumpSpeed : float = 1;
 private var rb: Rigidbody;
 
 function Start () {
 rb = GetComponent.<Rigidbody>();
 }
 
 function FixedUpdate () {
         var targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
         targetVelocity = transform.TransformDirection(targetVelocity)*MoveSpeed;
  
         var velocity = rb.velocity;
         var velocityChange = (targetVelocity - velocity);
         velocityChange.y = 0;
         rb.AddForce(velocityChange, ForceMode.VelocityChange);
         
         if (Input.GetButtonDown("Jump")) {
         rb.velocity = Vector3(0,JumpSpeed,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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Pendantic · Mar 13, 2015 at 05:57 AM

This isn't a perfect solution but if you make a physics material and make it's friction 0 then attach it to the player this stops all stickiness. If you do however want some friction for the ground, you can make another collider for the ground and just position this at the feet of the character. I've done this a lot and it's worked really well.

Comment
Add comment · Show 2 · 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 SanderN · Mar 13, 2015 at 12:57 PM 0
Share

This solution actually works more for me at this point of the development. Simple, easy, physics based- everything I was looking for. This provably works better when you are developing a physics based game. Also I feel like this solutions causes less bugs down the road too.

avatar image FOXAcemond · Jun 11, 2020 at 08:58 PM 0
Share

Thanks, finally the last piece I needed to find the CharacterController behavior back with a rigidbody approach. Finally an acceptable custom character controller!

avatar image
1

Answer by Mubanga · Mar 13, 2015 at 01:37 AM

You can add a trigger or a raycast to you character that checks just a lil bit in front of your collider. If that trigger finds something you can slide against, you disable movement in the direction of the wall and you can even slow down your decent if you wish.

Comment
Add comment · Show 7 · 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 SanderN · Mar 13, 2015 at 01:51 AM 0
Share

I thought about it too but solution like this would be REALLY sloppy, the whole idea of it is to be really smooth. I need the character to slide up depending on the angel it hits the wall. If I jump into the wall really close it should slide up until it has used up all of it's 'kinetic energy' and then it would fall down like in real world.

avatar image Mubanga · Mar 13, 2015 at 02:21 AM 0
Share

if you stop velocity in the x direction before your collider hits the wall you should get exactly that. I had the same problem a while ago. I will see if I can find my code for that project.

avatar image SanderN · Mar 13, 2015 at 02:45 AM 0
Share

I might try something like that then just see if it works and how well it works, using raycasts is provably the best way of doing that. But I still need to have air control after I hit the wall too so I'm not sure how to disable velocity X in only one X direction when using GetAxis("Horizontal"). I might need to make the script longer by defining left and right individually.

avatar image Mubanga · Mar 13, 2015 at 03:28 AM 0
Share

GetAxis("Horizontal") gives a float between -1 (left) and 1 (right) so to disable movement to the right you do if (hAxis > 0) hAxis = 0;

avatar image SanderN · Mar 13, 2015 at 03:46 AM 0
Share

Ok I guess that answers that question. Definitely will try that then in few hours to see if it works.

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.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Sliding along ramps in a "wave-like" side-scroller 1 Answer

camera smooth stop (continuously sliding), on touch end 0 Answers

Get all child not working? 1 Answer

Help with a movement script. 1 Answer

Rigidbody -- Box Collider Collision Detection 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