- Home /
Question by
ThoraxdeImpaler · Apr 19, 2014 at 02:38 AM ·
jump
Making a simple 2-D Jump script
I can not believe how difficult it has been for me to create a jump script. I have spent around 6 hours today looking through various threads on this forum, yet to no avail. Every implementation seems to get me the same results, I can jump infinitely with varying heights... I am a beginner to C# and I would greatly appreciate if you guys could help me a little bit.
using UnityEngine;
using System.Collections;
public class PlayerScript : MonoBehaviour {
// Use this for initialization
public enum State{
normal,
jumping
}
public State state;
public bool canJump = true;
public float j;
// Update is called once per frame
void Update() {
float inputX = Input.GetAxis ("Horizontal");
float inputY = Input.GetAxis ("Vertical");
if (Input.GetButtonDown ("Jump")) Jump();
Vector2 speed = new Vector2(25,25);
Vector3 movement = new Vector3(speed.x * inputX, speed.y * inputY, 0);
j = Input.GetAxis ("Jump");
Vector4 jumping = new Vector4 (0,speed.y * j, 0);
movement *= Time.deltaTime;
transform.Translate (movement);
transform.Translate(jumping);
jumping *= Time.deltaTime;
}
}
This is my code prior to me trying, unsuccessfully, to get my character to jump. :P
Comment
Your answer

Follow this Question
Related Questions
I need character only jump 1 Answer
Jumping through the roof! 1 Answer
How to make smooth jump? 1 Answer
Simple wall jump 0 Answers
2D box collider (character floating) 1 Answer