質問編集履歴
5
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -60,8 +60,7 @@
|
|
60
60
|
if (direction.sqrMagnitude > 0.01f)
|
61
61
|
{
|
62
62
|
Vector3 forward = Vector3.Slerp(transform.forward, direction, rotate_speed * Time.deltaTime / Vector3.Angle(transform.forward, direction));
|
63
|
-
transform.LookAt(transform.position + forward)
|
63
|
+
transform.LookAt(transform.position + forward);
|
64
|
-
|
65
64
|
}
|
66
65
|
|
67
66
|
if (Input.GetKeyDown(KeyCode.Space))
|
4
ソースの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,4 +9,73 @@
|
|
9
9
|
右を押したら右に、
|
10
10
|
上を押したら画面奥に
|
11
11
|
下を押したら画面手前側に、
|
12
|
-
左を押したら左に移動する方法をおしえてください!
|
12
|
+
左を押したら左に移動する方法をおしえてください!
|
13
|
+
|
14
|
+
|
15
|
+
+++++++++++++++++++追記++++++++++++++++
|
16
|
+
|
17
|
+
調べてここまでは作成することができました。
|
18
|
+
前左右は問題ないのですが、後ろだけワールド座標の動きになり、かならず同じ向きに下がります。
|
19
|
+
それに加えバックするときだけがたがたします。
|
20
|
+
```lang-C#
|
21
|
+
using UnityEngine;
|
22
|
+
using System.Collections;
|
23
|
+
|
24
|
+
public class Player : MonoBehaviour {
|
25
|
+
|
26
|
+
Vector3 direction;
|
27
|
+
//移動速度
|
28
|
+
public float move_speed = 5f;
|
29
|
+
//回転速度
|
30
|
+
public float rotate_speed = 180f;
|
31
|
+
//ジャンプ速度
|
32
|
+
public float jump_speed = 5f;
|
33
|
+
//重力
|
34
|
+
private float gravity=20f;
|
35
|
+
//アニメーターコンポーネント
|
36
|
+
Animator anim;
|
37
|
+
//キャラコントローラー
|
38
|
+
CharacterController chara;
|
39
|
+
|
40
|
+
|
41
|
+
Transform cam_trans;
|
42
|
+
// Use this for initialization
|
43
|
+
void Start () {
|
44
|
+
chara = GetComponent<CharacterController>();
|
45
|
+
anim = GetComponentInChildren<Animator>();
|
46
|
+
cam_trans = GameObject.Find("Main Camera").GetComponent<Transform>();
|
47
|
+
}
|
48
|
+
|
49
|
+
// Update is called once per frame
|
50
|
+
void Update () {
|
51
|
+
|
52
|
+
if (chara.isGrounded)
|
53
|
+
{
|
54
|
+
|
55
|
+
// direction = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
|
56
|
+
direction = (cam_trans.transform.right * Input.GetAxis("Horizontal")) +
|
57
|
+
(cam_trans.transform.forward * Input.GetAxis("Vertical"));
|
58
|
+
|
59
|
+
|
60
|
+
if (direction.sqrMagnitude > 0.01f)
|
61
|
+
{
|
62
|
+
Vector3 forward = Vector3.Slerp(transform.forward, direction, rotate_speed * Time.deltaTime / Vector3.Angle(transform.forward, direction));
|
63
|
+
transform.LookAt(transform.position + forward);
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
if (Input.GetKeyDown(KeyCode.Space))
|
68
|
+
{
|
69
|
+
direction.y = jump_speed;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
direction.y -= gravity * Time.deltaTime;
|
74
|
+
|
75
|
+
chara.Move(direction * Time.deltaTime * move_speed);
|
76
|
+
anim.SetFloat("Speed", chara.velocity.magnitude);
|
77
|
+
}
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
```
|
3
変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
unity キャラ視点での移動方法
|
1
|
+
unity 3Dキャラ視点での移動方法
|
body
CHANGED
File without changes
|
2
変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,6 +9,4 @@
|
|
9
9
|
右を押したら右に、
|
10
10
|
上を押したら画面奥に
|
11
11
|
下を押したら画面手前側に、
|
12
|
-
左を押したら左に移動する方法をおしえてください!
|
12
|
+
左を押したら左に移動する方法をおしえてください!
|
13
|
-
|
14
|
-
もう少し自分でも考えてみようと思います。
|
1
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,4 +9,6 @@
|
|
9
9
|
右を押したら右に、
|
10
10
|
上を押したら画面奥に
|
11
11
|
下を押したら画面手前側に、
|
12
|
-
左を押したら左に移動する方法をおしえてください!
|
12
|
+
左を押したら左に移動する方法をおしえてください!
|
13
|
+
|
14
|
+
もう少し自分でも考えてみようと思います。
|