(how to make a fps game) how can I make it possible for the charakter to jump and sprint?

Updated on May 31, 2017 in [A] Brackeys Courses
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on May 18, 2017

I have the player motor:
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMotor : MonoBehaviour {
private Rigidbody rB;
public Vector3 velocity = Vector3.zero;

// Use this for initialization
void Start () {
rB = GetComponent ();
}

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

void FixedUpdate()
{
PerformMovement ();
}

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

and the controller:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour {

public float speed = 5f;
private PlayerMotor motor;

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

void Update()
{
float _xMov = Input.GetAxisRaw(“Horizontal”);
float _zMov = Input.GetAxisRaw (“Vertical”);

Vector3 _movHorizontal = transform.right * _xMov;
Vector3 _movVertical = transform.forward * _zMov;

Vector3 _velocity = (_movHorizontal + _movVertical).normalized * speed;

motor.Move (_velocity);

if(Input.GetKey(“shift”))
{
speed = 10f;
}
}
}

how do I sprint and make my player jump?

  • Liked by
Reply
1 on May 19, 2017
on May 31, 2017

sry. I am used to unity answers but I came here because I teach programming to myself and do not really know enough to gain reputation

Show more replies
  • Liked by
Reply
Cancel