- Home /
Question by
unity_AweRSs-5V4ksFQ · May 17, 2018 at 04:08 PM ·
movementjumpjumping
Jump in multiplayer,How can I Jump Multiplayer
using UnityEngine;
using UnityEngine.Networking;
public class PlayerController : NetworkBehaviour
{
void Update()
{
if (!isLocalPlayer)
{
return;
}
var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
var up = Input.GetAxis("Jump") * Time.deltaTime * 3.0f;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
}
}
I can move but don´t jump, using UnityEngine; using UnityEngine.Networking;
public class PlayerController : NetworkBehaviour
{
void Update()
{
if (!isLocalPlayer)
{
return;
}
var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
var up = Input.GetAxis("Jump") * Time.deltaTime * 3.0f;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
}
}
I can Move but don´t jump
Comment
Answer by Temseii · May 17, 2018 at 04:13 PM
You declared "up" but you aren't actually doing anything with it
Answer by Spacejet13 · May 17, 2018 at 11:47 PM
You can simply add a force to the rigidbody to move it up . .
public Rigidbody rb; //set it in the inspector
public float jump; //set it in the inspector
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(0, jump * Time.deltatime, 0, ForceMode.Impulse);
}
}
This should do the trick for jumping!
Note: Forcemode.Impulse is very important as it applies a sudden force to rigidbody, like jumping