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 NopkarCraft · Oct 09, 2020 at 05:53 PM · movementrigidbody2d

Remove Acceleration of Player

I wanna make a Movement Code for a Plataform 2D. I know that my code isn't good, but works good for movement, jump and Double Jump. I'm using RigidBody2D AddForce to Move and Jump, and using "Velocity X = 0" to remove acceleration. This worked, but now I want to add Wall Jump and I can't use AddForce or Velocity on X Axys cause the Velocity X is Constantly 0. Can I do anything or I need to change all my movement System?

(Sorry my English) Code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ControlaRe : MonoBehaviour {
 
     public int velR, puloR, puloWall;
     public Rigidbody2D rigidB;
     public bool direiRe;
     //Teste Bools
     public bool dJump, wJump, bJump;
     public static int maxJump;
 
     void Start () {
         maxJump = 0;
         direiRe = true;
         rigidB = gameObject.GetComponent<Rigidbody2D>();
     }
     
     void Update () {
         //rigidB.velocity = new Vector2(0, rigidB.velocity.y);
         
 
         // Movimentos
         if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
         {
             if (!ConfereChao.colidiP || !direiRe)
             {
                 MoveRe(); direiRe = true;
             }
 
         }
         if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
         {
             if (!ConfereChao.colidiP || direiRe)
             {
                 MoveRe(-1); direiRe = false;
             }
 
 
         }
         if (Input.GetKeyDown(KeyCode.UpArrow))
         {
             if (ConfereChao.colidiC || (maxJump == 1 && dJump))
             {
                 if (!ConfereChao.colidiC)
                 {
                     rigidB.velocity = new Vector2(rigidB.velocity.x, 0);
                 }
                 rigidB.AddForce(Vector2.up * puloR);
                 maxJump++;
             }
 
             if (ConfereChao.colidiP && wJump && !ConfereChao.colidiC)
             {
                 rigidB.velocity = new Vector2(rigidB.velocity.x, 0);
                 rigidB.AddForce(Vector2.up * puloWall);
             }
         }
 
 
         // Sprite Lado
         if (direiRe == true)
         {
             GameObject.Find("TextuRe").transform.rotation = Quaternion.Euler(0, 0, 0);
         }
         else
         {
             GameObject.Find("TextuRe").transform.rotation = Quaternion.Euler(0, 180, 0);
         }
 
 
 
     }
 
     void MoveRe(int leftRight = 1){
         rigidB.AddForce(Vector2.right*velR*leftRight);
     }
 
 }

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
0

Answer by danidani360 · Oct 11, 2020 at 01:01 AM

I'm not sure if this will help your jumping issue, but to change the movement of the player you can use "Input.GetAxisRaw". This will give you a value of -1 (left), 0 (not moving), or 1 (right) as the left and right buttons are pressed. Multiply this value by speed for the player to move. This way the player does not accelerate, but immediately hits the desired speed. Hopefully that resolves your issue!

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

207 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

Related Questions

Disabling diagonal movement in Unity 5 2D? (using C#) 1 Answer

How to make cars rotate towards a waypoint while turning? 0 Answers

2D Faux Gravity using a Point Effector? 1 Answer

Rigid Body Movement (Mobile Issue) 3 Answers

Bounce into the air 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