-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.cs
59 lines (47 loc) · 1.39 KB
/
Player.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
float speed = 1.0F;
float gravity = 100000.0F;
bool isGrounded = false;
bool isJumping = false;
float jumpTime = 0;
float maxJumpTime = Mathf.PI / 2;
float jumpSpeedMultiplier = 4.0F;
Vector3 currentPos;
// Use this for initialization
void Start () {
Physics.gravity = new Vector3(0, 0, gravity);
transform.rigidbody.mass = 100.0F;
currentPos = transform.localPosition;
}
// Update is called once per frame
void Update()
{
transform.Translate(new Vector3(Input.GetAxis("Horizontal") * (speed * 100) * Time.deltaTime, 0, 0));
if (Input.GetKeyDown(KeyCode.UpArrow))
{
if (jumpTime == 0)
{
currentPos = transform.localPosition;
isJumping = true;
}
}
Jumping();
}
void Jumping()
{
if (isJumping)
{
if (jumpTime < maxJumpTime)
{
jumpTime += 1 * (Time.deltaTime * jumpSpeedMultiplier);
transform.localPosition = new Vector3(
transform.localPosition.x,
currentPos.y + (Mathf.Sin(jumpTime) * 200),
transform.localPosition.z);
}
else { jumpTime = 0; isJumping = false; }
}
}
}