-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController6.cs
More file actions
62 lines (50 loc) · 1.79 KB
/
Controller6.cs
File metadata and controls
62 lines (50 loc) · 1.79 KB
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
60
61
62
#if NORMCORE
using System.Collections;
using System.Collections.Generic;
using Normal.Realtime;
using UnityEngine;
public class Controller6 : MonoBehaviour
{
//Rigidbody rb;
public float speed = 5f;
public float jumpAmount = 15f;
public float gravityScale = 10f;
public Rigidbody rb = null;
private RealtimeView _realtimeView;
private RealtimeTransform _realtimeTransform;
private void Awake()
{
_realtimeView = GetComponent<RealtimeView>();
_realtimeTransform = GetComponent<RealtimeTransform>();
}
void Start()
{
//Fetch the Rigidbody from the GameObject with this script attached
//rb = GetComponent<Rigidbody>();
}
private void Update()
{
// If this CubePlayer prefab is not owned by this client, bail.
if (!_realtimeView.isOwnedLocallySelf)
return;
// Make sure we own the transform so that RealtimeTransform knows to use this client's transform to synchronize remote clients.
_realtimeTransform.RequestOwnership();
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector2.up * jumpAmount, ForceMode.Impulse);
}
}
void FixedUpdate()
{
// If this CubePlayer prefab is not owned by this client, bail.
if (!_realtimeView.isOwnedLocallySelf)
return;
rb.AddForce(Physics.gravity * (gravityScale - 1) * rb.mass);
//Store user input as a movement vector
Vector3 m_Input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
//Apply the movement vector to the current position, which is
//multiplied by deltaTime and speed for a smooth MovePosition
rb.MovePosition(transform.position + m_Input * Time.deltaTime * speed);
}
}
#endif