- Home /
How should I implement jumping into this script?
When I try to implement jumping into this script, the "playerRb.velocity = playerTf.right xInput velocityMultiplier + playerTf.forward zInput velocityMultiplier" overrides and cancels the added velocity/force. Any help welcome :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
// Ground Checker
bool isGrounded;
public Transform groundCheckerTf;
public LayerMask groundLayer;
// Input and forward and sideways movement
float xInput;
float zInput;
public Rigidbody playerRb;
public Transform playerTf;
public float velocityMultiplier;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// Ground Checker
isGrounded = Physics.CheckSphere(groundCheckerTf.position, 0.05f, groundLayer);
// Forward and sideways movement
xInput = Input.GetAxis("Horizontal");
zInput = Input.GetAxis("Vertical");
playerRb.velocity = playerTf.right * xInput * velocityMultiplier + playerTf.forward * zInput * velocityMultiplier;
}
}
Comment
Your answer
Follow this Question
Related Questions
How can I change vector speed? 1 Answer
Velocity bug with hinge joints forces in C# 0 Answers
rigidbody.Velocity stops gravity 2 Answers
ForceMode.Impulse Doesnt always fire. 2 Answers