How to make moving backwards slower than moving forwards

I’m currently using this (slightly adapted) PlayerController script which I copied from here:

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

public class PlayerController : MonoBehaviour

    public float movementSpeed = 9.0f;

    // Use this for initialization
    void Start()

    // Update is called once per frame
    void Update()
        var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
        var z = Input.GetAxis("Vertical") * Time.deltaTime * movementSpeed;
        transform.Rotate(0, x, 0);
        transform.Translate(0, 0, z);

I’d like to make the movement speed when moving backward into say 70% of normal.

I tried using an if statement on z saying that if z<0, z=0.7*z, but that didn't seem to work since apparently z was a double which couldn't be turned into a float without a cast. I didn't want to cast since (according to MS) "Casting is required when information **might be lost** in the conversion, or when the conversion might not succeed for other reasons. "

Anyone know how to solve this?

Thanks in advance!

This might help you . My suggestion is using by KeyCode

 Vector3 temp =;

void Update(){
 if (Input.GetKey (KeyCode.W)
       //movementSpeedForward here
       temp += transform.forward;
 if (Input.GetKey (KeyCode.S))
         //movementSpeedBackward here
         temp += transform.forward * -1;


Hope it helps you :). Its much better :slight_smile: