0
\$\begingroup\$

Wanna to make player controller like in game "Overcooked".

Trailer with gameplay.

My current player controller.

enter image description here

PlayerController.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControllerTransform : MonoBehaviour {

    private string moveInputAxis = "Vertical";
    private string turnInputAxis = "Horizontal";

    public float rotationRate = 360f;
    public float moveSpeed = 1;


    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () 
    {
        float moveAxis = Input.GetAxis (moveInputAxis);
        float turnAxis = Input.GetAxis (turnInputAxis);

        //Обновляет каждый кадр наше положение и поворот
        ApplyInput (moveAxis, turnAxis);
    }

    private void ApplyInput(float moveInput, float turnInput)
    {
        Move (moveInput);
        Turn(turnInput);
    }

    private void Move(float input)
    {
        transform.Translate (Vector3.forward*input*moveSpeed);//Можно добавить Time.DeltaTime
    }

    private void Turn(float input)
    {
        transform.Rotate (0,input * rotationRate * Time.deltaTime,0);
    }
}

P.S. "Horizontal" keys in my code just rotate player. Every key "WASD" must move my player at that direction which player look. I mean A-left, W-top, D-right, S-bottom. My code A-D-rotation, W-forward, S-backward.(English not my first language.)

Thanks for attention and help!

\$\endgroup\$
  • 1
    \$\begingroup\$ @Artik Slayer Your comment regarding your current WASD behavour and how you want your WASD behavour to actually work - basically add that information to your question. Not everyone reads the comment section of the question and the more information you have in your question post, the better. Also, if the character's direction for example is Z-forward and you press A to move to the left, do you want the character's direction to snap to that specific direction or should the direction smoothly change to the correct direction (like how the character movement in the posted video works)? \$\endgroup\$ – Daniel_1985 Jan 13 '19 at 23:26
  • \$\begingroup\$ Sure. Yes, like in the video. (It's will be crime if I ask people try the game by checking controller?).p.s. Later I wanna add some Blender-stuff, but I am newbee in that) \$\endgroup\$ – Artik Slayer Jan 13 '19 at 23:52
  • \$\begingroup\$ Do you want to remove the rotation of your character or add horizontal movement as you rotate? What you want the code to do isn't very clear. Your movement right now looks very good if you're trying to imitate overcooked. \$\endgroup\$ – JeffBrin Jan 14 '19 at 1:56
  • \$\begingroup\$ I did not play that game and it's not 100% clear from the trailer how the controls of the game work. I would assume the character moves into the direction of the thumbstick. Is that correct? Do the characters have some momentum which causes them to take some time to change direction or can they turn immediately? Do they accelerate and decelerate or does input map to movement 1:1? \$\endgroup\$ – Philipp Jan 14 '19 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.