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 Frienldmushroom · Mar 21, 2020 at 04:18 PM · 3rd person controller

How to add Countermovement?

Hi, In the moment I am making a very simple 3D platformer with a Rigidbody 3D. And I want to add Countermovement to get a much more snappy movement. How can I do that?

 using System.Collections;
 
 using System.Collections.Generic;
 
 using UnityEngine;
 
 public class Player3DMovement : MonoBehaviour
 
 {
 
    private Rigidbody rb;
 
    public float speed;
 
    public float maxSpeed;
 
    public float counterMovement;
 
    private float applySpeed;
 
    Vector3 move;
 
    // Start is called before the first frame update
 
    void Start()
 
    {
 
        rb = GetComponent<Rigidbody>();
 
    }
 
    // Update is called once per frame
 
    void Update()
 
    {
 
        float x = Input.GetAxis("Horizontal");
 
        float z = Input.GetAxis("Vertical");
 
   
 
        Vector3 move = transform.right * x + transform.forward * z;
 
        if(rb.velocity.magnitude > maxSpeed)
 
        {
 
            rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
 
        }
 
        else
 
        {
 
           rb.AddForce(move * speed);
 
        }
 
    }
 
   
 
 }
 

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 Smartoom7 · Aug 21, 2020 at 01:14 AM 0
Share

I am waiting for the answer just like you!

avatar image N-8-D-e-v Smartoom7 · Aug 27, 2020 at 11:31 PM 0
Share

@Smartoom7 I have an answer

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by N-8-D-e-v · Aug 21, 2020 at 03:16 AM

There are a couple ways you could do this

First off, you could just have 0 velocity on each axis when not pressing certain keys, this will get you incredibly snappy movement

 if (Input.GetButtonUp("Horizontal")
 {
       rb.velocity = new Vector3(0, rb.velocity.y, rb.velocity.z);
 }
 if (Input.GetButtonUp("Vertical")
 {
       rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, 0);
 }

Or, you could do some (somewhat) simple trig math and calculate the direction the player is facing with cosine and sine https://www.youtube.com/watch?v=-dGi2Ffdiuk (this tutorial will help with that, but will not have the scripts you are looking for.) and then just add force in the opposite direction the player is travelling in.

Possibly the simplest method (yes even simpler than the first one) Would be to apply a physics material to the ground that has a high amount of friction

I hope this helps you, feel free to ask any questions if you are confused and want more help!

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

125 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

Related Questions

Animation 101: How does an Animation component work with a hierarchy? 0 Answers

Animation event triggering step on frame 0 Answers

How do I edit this to make my character move based on the Camera Axis instead of World Axis? 0 Answers

How do I attach multiple animations at a time to a character? And how to I make them trigger when a user presses keys? 0 Answers

3rd person controller using GUI.button Windows Standalone 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