How do i control my character in unity? And what buttons do i press? Can anyone help plz?

Updated on November 4, 2017 in [D] Game Dev. gossip
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on November 4, 2017

Could anyone help me please i have been following a tutorial on brackets on how to make an fps game and i go to run my game (There are absolutely no errors in the code ) but when i hit the keys W A S and D or the arrows it doesn’t do anything and i think there are different keys that you have to press in order to move your character but i haven’t figured it out yet, could anybody help me please?

 

These are my two scripts and my only 2 that i have so far:

 

PlayerController:

 

[ using UnityEngine;

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

    private Vector3 velocity = Vector3.zero;

    private Rigidbody rb;

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

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

    void FixedUpdate()
    {
        PerformMovement();
    }

    void PerformMovement()
    {
        if (velocity != Vector3.zero)
        {
            rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
        }
    }

}
]

[/code]

 

AND my other script which is PlayerMotor:

 

[ using UnityEngine;

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

    private Vector3 velocity = Vector3.zero;

    private Rigidbody rb;

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

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

    void FixedUpdate()
    {
        PerformMovement();
    }

    void PerformMovement()
    {
        if (velocity != Vector3.zero)
        {
            rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
        }
    }

}
]

[/code]

 

p.s There are no errors in the script that the game has dented just 2 yellow warnings:

    1. Assets/PlayerController.cs(19,9): warning CS0219: The variable `zMov’ is assigned but its value is never used

 

    1. Assets/PlayerMotor.cs(17,3): warning CS1717: Assignment made to same variable; did you mean to assign something else?

 

  • Liked by
Reply
1 on November 4, 2017
public void Move(Vector3 velocity)     
{
velocity = velocity;    
}
From Greenelecboy

 It’s probably ment to be

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

 

And you copied two times the PlayerMotor instead of one time the PlayerController

on November 4, 2017

Oh thanks for pointing that out didn’t see that thank you very much for your help!!! :]

Show more replies
  • Liked by
Reply
Cancel