Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed May 06 at 07:16 PM by CeratoRaptor for the following reason:

Found Answer

avatar image
0
Question by CeratoRaptor · Jan 26 at 04:23 AM · inputcharactercontroller

Moving player using character controller with new input system

Hey everyone! I've been trying to learn Unity's new input system. I prefer the character controller over using a rigid body, but it doesn't seem that there are any tutorials on using the character controller. I've tried figuring it out myself, but the player doesn't move when I press the assigned keys. I saw that it works as debug logs come out when I press the button, but for some reason, no matter what order I put the code in, the player won't move. I have the script set up properly and everything, I just need to figure out how to use the new input system with the character controller. I know that with a rigid body you can use add force, and everything works. But you can't do that with the character controller. I am using a public void outside of Update. If anyone could show me a way to do it, that'd be appreciated.

Thanks to everyone who helps!

Comment
Add comment · Show 1
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 aidangig56 · Apr 17 at 11:05 PM 0
Share

I assume you don't need help but where is the code that you are using...

1 Reply

  • Sort: 
avatar image
0

Answer by UnityPlum · Jan 28 at 11:31 PM

Alrighty, basic rundown. sideMovement will be equal to one when "D" is pressed and -1 when "A" is pressed. forwardMovement will be 1 with "W" and -1 with "S"

 float sideMovement = Input.GetAxis ("Horizontal")
 float forwardMovement = Input.GetAxis("Vertical")

This will tell you if the player jumped

 bool canBhop = false;
 bool jumped = Input.GetKeyDown (KeyCode.Space);
 if (canBhop) {
     jumped = Input.GetKey (KeyCode.Space);
 }

And this is how you move the character:

 // moveSpeed is a float
 // velocity is some Vector3 with velocity
 // this function will move character by x every time you call it.
 
 GetComponent<CharacterController>().Move (velocity * moveSpeed * Time.deltaTime);

Here is a quick script I just made:

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CharacterMovement : MonoBehaviour {
     public CharacterController cc;
     public float moveSpeed;
     public float jumpSpeed;
     public float gravity;
     public Vector3 velocity;
 
     void Start()
     {
         cc = GetComponent<CharacterController>();
     }
 
     public void Update()
     {
         float sideMovement = Input.GetAxis ("Horizontal");
         float forwardMovement = Input.GetAxis("Vertical");
 
         velocity.x = sideMovement;
         velocity.z = forwardMovement;
         
         bool isGrounded = cc.isGrounded;
         bool canBhop = false;
         bool jumped = Input.GetKeyDown (KeyCode.Space);
 
         if (canBhop) {
             jumped = Input.GetKey (KeyCode.Space);
         }
 
         if (jumped && isGrounded)
         {
             velocity.y = jumpSpeed;
         } else if (!isGrounded)
         {
             velocity.y -= gravity;
         }
 
         cc.Move ((transform.rotation * velocity) * moveSpeed * Time.deltaTime);
     }
     
 }


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 aidangig56 · Apr 17 at 11:04 PM 0
Share

The user wanted the new input system. Input.GetAxis as an example is the old, legacy system....

Follow this Question

Answers Answers and Comments

180 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

Related Questions

unity input system help 2 Answers

Rotation of character resets when joystick is released 3 Answers

My player keeps launching into the sky 1 Answer

changing input from mouse to keyboard key 2 Answers

Don't jump continuously when button held down 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