Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
This question was closed Jul 04, 2017 at 03:02 PM by Hellium for the following reason:

Duplicate Question

avatar image
2
Question by Alfrey_Cruz8133 · Jul 04, 2017 at 02:15 PM · javascriptcharactercharacter movementfps controller

How to move the Character using WASD

Hi!

First of all, I dont want to use the FPS Controller Prefab and a C# script (peace hahaha)

So how do I move my character to go forward where Im currently looking at.

Thnks!

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 Hellium · Jul 04, 2017 at 03:01 PM 1
Share

Error 404 : No effort found

3 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by efeguclu · Jul 04, 2017 at 02:23 PM

try this(Don't Forget To Attach a rigidbody to your object and make sure script is attached to object that is going to move) :

     private void Update() {
         Rigidbody rb = GetComponent<Rigidbody>();
         if (Input.GetKey(KeyCode.A))
             rb.AddForce(Vector3.left);
         if (Input.GetKey(KeyCode.D))
             rb.AddForce(Vector3.right);
         if (Input.GetKey(KeyCode.W))
             rb.AddForce(Vector3.up);
         if (Input.GetKey(KeyCode.S))
             rb.AddForce(Vector3.down);
 
     }

and JS :

         private function Update() {
             var rb = GetComponent.<Rigidbody>();
             if (Input.GetKey(KeyCode.A))
                 rb.AddForce(Vector3.left);
             if (Input.GetKey(KeyCode.D))
                 rb.AddForce(Vector3.right);
             if (Input.GetKey(KeyCode.W))
                 rb.AddForce(Vector3.up);
             if (Input.GetKey(KeyCode.S))
                 rb.AddForce(Vector3.down);
     
         }


Comment
Add comment · Show 5 · 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 Alfrey_Cruz8133 · Jul 04, 2017 at 02:29 PM 0
Share

JS or C#???

avatar image efeguclu Alfrey_Cruz8133 · Jul 04, 2017 at 02:31 PM 0
Share

It's C# I'll write JS into answer wait..

avatar image Alfrey_Cruz8133 · Jul 05, 2017 at 11:59 AM 0
Share

Isnt this about rolling a ball? I need the FPS controller one

avatar image trollyt404 · Sep 16, 2017 at 09:10 PM 0
Share

How do I add the object? (And can I have another script to move to camera with mouse?)

avatar image trollyt404 · Sep 16, 2017 at 09:14 PM 0
Share

Please help me do this https://www.youtube.com/watch?time_continue=42&v=df5G8s-$$anonymous$$VQ4.

avatar image
2

Answer by FunIsDangerous · Jul 04, 2017 at 02:41 PM

Here is my code with character controller. It doesn't have gravity by default so I added it. I assume you want it for a 3d game

 public float speed = 5;
 public float gravity = -5;
 
 float velocityY = 0; 
 
 CharacterController controller;
 
 void Start()
 {
     controller = GetComponent<CharacterController>();
 }
 
 void Update()
 {
     velocityY += gravity * Time.deltaTime;
 
     Vector3 input = new Vector3(Input.GetAxisRaw("Horizontal"), 0 Input.GetAxisRaw("Vertical"));
     input = input.normalized;
 
     Vector3 temp = Vector3.zero;
     if (input.z == 1)
     {
         temp += transform.forward;
     }
     else if (input.z == -1)
     {
         temp += transform.forward * -1;
     }
 
     if (input.x == 1)
     {
         temp += transform.right;
     }
     else if (input.x == -1)
     {
         temp += transform.right * -1;
     }
 
     Vector3 velocity = temp * speed;
     velocity.y = velocityY;
     
     controller.Move(velocity * Time.deltaTime);
 
     if (controller.isGrounded)
     {
         velocityY = 0;
     }
 }

This will also work with a controller. The main advantage of using a character controller over rigidbody is it can go up slopes. Also, if you want jumping, it's simple enough, the axis is Input.GetAxisRaw("Jump"), and just reset velocityY to how far you want to jump

Comment
Add comment · Show 3 · 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 Alfrey_Cruz8133 · Jul 04, 2017 at 02:55 PM 0
Share

is it JS or C#?

avatar image efeguclu Alfrey_Cruz8133 · Jul 04, 2017 at 02:57 PM 0
Share

check my answer I have C# And JS And If you see void in script it is C# but if you see function so it isi JS

avatar image FunIsDangerous Alfrey_Cruz8133 · Jul 04, 2017 at 03:01 PM 0
Share

^ exactly. This is c#

avatar image
1

Answer by Shrikky23 · Jul 04, 2017 at 02:32 PM

     private int speed = 10;
     
     public void Move()
     {
     
     Vector3 Movement = new Vector3 (Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical");
     
     player.transform.position += Movement * speed * Time.DeltaTime;
     
     }
     
    Make sure the Project settings -> Input has Horizontal and vertical assigned to WASD/ Arrow keys.
 
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 DarthMelange · Feb 16, 2021 at 11:43 AM 0
Share
 public float speed =20;

public float turnSpeed = 50f; void Update () { if (Input.GetKey (KeyCode.W)){ transform.Translate(Vector3.forward*speed*Time.deltaTime); } if (Input.GetKey (KeyCode.S)){ transform.Translate(-Vector3.forward*speed*Time.deltaTime); }

     if (Input.GetKey (KeyCode.D)){
         transform.Rotate(Vector3.up,turnSpeed * Time.deltaTime);

} if (Input.GetKey (KeyCode.A)){ transform.Rotate(Vector3.up,-turnSpeed * Time.deltaTime); } }

Follow this Question

Answers Answers and Comments

126 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

Related Questions

Error CS0103 0 Answers

Complete character design/animation/control tutorial 0 Answers

My Character dosen´t move 0 Answers

Constant Player Spinning to the left. 1 Answer

How to flip my character with this script 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