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 /
  • Help Room /
This question was closed May 30, 2017 at 06:03 AM by Inverrtted for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Inverrtted · May 29, 2017 at 09:14 PM · movementplayerscript.controllermotor

I can't move my player in a fps?

Hi, I followed an online tutorial (by Brackeys) on making a fps. I got to a point where I have made the player, and I am coding the movement. I have followed everything correctly, but when Brackeys' checks the game, he can move. Whereas, I can not. I have both of my scripts ready if asked for, here is player controller - using UnityEngine;

[RequireComponent(typeof(PlayerMotor))] public class PlayerController : MonoBehaviour {

 [SerializeField]
 private float speed = 5f;

 private PlayerMotor motor;

 void Start ()
 {
     motor = GetComponent<PlayerMotor>();

 }

 void Update ()
 {
     // Calculate movement velocity as a 3D Vector
     float xMov = Input.GetAxisRaw("Horizontal");
     float zMov = Input.GetAxisRaw("Vertical");

     Vector3 movHorizontal = transform.right * xMov;
     Vector3 movVertical = transform.forward * zMov;

     // Final movement vector
     Vector3 velocity = (movHorizontal + movVertical).normalized * speed;

     // Apply movement
     motor.Move(velocity);
 }

} And here is Player Motor - using UnityEngine;

[RequireComponent(typeof(Rigidbody))] public class PlayerMotor : MonoBehaviour {

 private Vector3 velocity = Vector3.zero;

 private Rigidbody rb;

 void Start ()
 {
     rb = GetComponent<Rigidbody>();
 }

 // Gets a movement vector
 public void Move (Vector3 velocity)
 {
     velocity = velocity;
 }

 // Run every physics iteration
 void FixedUpdate ()
 {
     PerformMovement();
 }

 //Perform movement based on velocity variable
 void PerformMovement ()
 {
     if(velocity != Vector3.zero)
     {
         rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);

} } }

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

  • Sort: 
avatar image
1

Answer by DFT-Games · May 29, 2017 at 11:05 PM

Hi @Inverrtted ,

You have an ambiguous naming in your Player Motor due to the velocity parameter that is also a field. You can solve it in two ways, one is to write the Move method like this:

 public void Move(Vector3 velocity)
 {
     this.velocity = velocity;
 }

The other is to just thence the parameter name, like this:

 public void Move(Vector3 newVelocity)
 {
     velocity = newVelocity;
 }

Both solutions work ;)

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 Inverrtted · May 30, 2017 at 06:03 AM 0
Share

Thank you! I was annoyed with myself, glad it's done now. You're a lifesaver! :)

Follow this Question

Answers Answers and Comments

137 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

Related Questions

Some problems with handmade basic player controller 0 Answers

How do I get a character to walk on walls and ceilings? 1 Answer

Why can my character controlled player can stand on the side of a block? 0 Answers

Top Down Character - Face direction of movement? 0 Answers

Object Player Movement stops working after Restarting Unity 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