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 xandermacleod · Jul 14, 2012 at 08:05 PM · collidervelocitygravityfallingfall

Object won't fall when I apply horizontal velocity and is colliding with wall.

Hi there.

Im currently trying to create a simple 2d platforming game, and im having a little trouble with my character when he collides with another object mid-fall/mid-jump. He is jumping, falling and walking sideways like i want him to. However, whenever he jumps into a wall or falls into a wall, if I hold down the 'walk left' or 'walk right' button (i.e. keep trying to get him to walk sideways into that wall), he freezes in mid air. Could anyone tell me how I might fix this?

Here is some of my script (Javascript):

     public var horizontal_speed : float = 5.0f;
 public var jump_Power : float = 15.0f;
 
 private var directionFacing : int = 1;
 private var isJumping : boolean = false;
 
 public function Update () : void {
 
  //Horizontal Movement
  if (Input.GetButton("Horizontal")) {
  // for directionFacing variable -----
  //            1 = character is facing right
  //            -1 = character is facing left
  directionFacing = Input.GetAxis("Horizontal") < 0 ? -1 : 1;
  rigidbody.velocity = new Vector3((directionFacing * horizontal_speed), rigidbody.velocity.y, 0);
  }
  
  //If character isn’t jumping
  if (!isJumping) { 
  //Jump
  if (Input.GetButton("Jump")) {
  isJumping = true;
  rigidbody.velocity = new Vector3(rigidbody.velocity.x, jump_Power, 0);
  }
  }
 }


Please note: I later on in this script have a section where "isJumping" is turned back to being false, but it involves a lot of raycast detection stuff that i dont think is relevant. If however you would like me to post that as well, Im more than happy to do so.

Currently the character has a box collider (not trigger) and a rigidbody. It is using gravity and 'is kinematic' is off. Constraints are set to freeze all rotation and z translation. Mass = 1. Walls and floor are also using box colliders (not trigger) - no rigidbodies on these.

I'm assuming when I hold down left or right the amount of velocity i am applying to the character is overpowering the effect of gravity, but i dont know how to stop this effect (plus it doesnt make sense to me that this should happen).

Can anyone please help? I dont mind if someone can suggest a C# solution as well, as it looks like it should be a fairly simple issue.

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 ScroodgeM · Jul 23, 2012 at 08:52 PM

a simple solution:

  • make a Physic Material and make it's friction to zero

  • assign it to wall's colliders

a complex solution

  • don't assign rigidbody.velocity directly. change it adding force

  • use FixedUpdate to interact with physics

  • detect collisions (OnCollisionEnter method) and possibilities to adding forces based on these collisions

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody y velocity is stuck on 0, gravity is not turned off. 2 Answers

Can't move when fall from high 1 Answer

How do i get the Y Velocity of my character? 1 Answer

Check if Rigidbody collider is grounded 3 Answers

Impulse to reach certain height? 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