質問編集履歴

2

コードの変更

2017/06/17 00:50

投稿

miiichat
miiichat

スコア72

test CHANGED
File without changes
test CHANGED
@@ -30,13 +30,15 @@
30
30
 
31
31
  {
32
32
 
33
- Vector3 screenPoint = Camera.main.WorldToScreenPoint (transform.position);
33
+ Vector3 screenPoint = Camera.main.WorldToScreenPoint (transform.position);
34
34
 
35
- Vector3 offset = transform.position - Camera.main.ScreenToWorldPoint
36
35
 
37
- (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
38
36
 
37
+ Vector3 offset = Camera.main.ScreenToWorldPoint
38
+
39
+ (new Vector3 (Input.mousePosition.x,Input.mousePosition.y, screenPoint.z)) - transform.position;
40
+
39
- gameObject.GetComponent<Rigidbody>().AddForce(offset);
41
+ gameObject.GetComponent<Rigidbody>().AddForce(offset * 10f);
40
42
 
41
43
  }
42
44
 

1

コードの変更

2017/06/17 00:50

投稿

miiichat
miiichat

スコア72

test CHANGED
File without changes
test CHANGED
@@ -30,13 +30,13 @@
30
30
 
31
31
  {
32
32
 
33
- float x = Input.mousePosition.x - transform.position.x;
33
+ Vector3 screenPoint = Camera.main.WorldToScreenPoint (transform.position);
34
34
 
35
- float y = Input.mousePosition.y - transform.position.z;
35
+ Vector3 offset = transform.position - Camera.main.ScreenToWorldPoint
36
36
 
37
- Vector3 vector3 = new Vector3(x,0,y);
37
+ (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
38
38
 
39
- gameObject.GetComponent<Rigidbody>().velocity = vector3 * 0.1f;
39
+ gameObject.GetComponent<Rigidbody>().AddForce(offset);
40
40
 
41
41
  }
42
42