2017-12-16 3 views
0

저는 유니티 자산 First Person Controller를 사용하여 플레이어의 움직임을 허용하고 주변을 둘러 볼 수있는 게임을 만들었습니다. 레이 캐스트가 쏘아 져서 총알이 생겨나는 곳에 십자형 머리를 넣었습니다. 특정 각도 이상의 총알이 발사되는 데는 아무런 문제가 없습니다. 총알은 십자선을 따라 가운데에서 오른쪽으로 쏘지 만 너무 멀리 내려다 보면 십자가가 더 이상 쏘지 않고 카메라에서 곧바로 쏠 수 있습니다.레이크 캐스트가 특정 각도를 지나서 응답하지 않습니다.

필자는 코드에서 아무 것도 찾을 수 없으므로 1 인칭 컨트롤러가 만드는 캡슐이 문제 일 수 있다고 생각합니다. VIDEO TO

LINK : https://youtu.be/zf2EuL7e_i4

총알

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 

public class BulletListener : MonoBehaviour { 
public Camera mainCamera; 
public BulletContoller bulletPrefab; 
public GameObject cursor; 
private Vector3 cursorPosition; 

void Update() { 
    if (Input.GetMouseButtonDown (0)) { 

     cursorPosition = cursor.transform.position; 

     //create ray from camera to mousePosition 
     Ray ray = mainCamera.ScreenPointToRay (cursorPosition); 

     //Create bullet from the prefab 
     BulletContoller newBullet = Instantiate (bulletPrefab.gameObject).GetComponent<BulletContoller>(); 

     //Make the new bullet start at camera 
     newBullet.transform.position = mainCamera.transform.position; 

     //set bullet direction 
     newBullet.SetDirection (ray.direction); 

     //Create Bullet Sound 
     AudioSource audio = GetComponent<AudioSource>(); 

     audio.Play(); 
    } 
} 
} 

Listener.cs 총알 Controller.cs

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 

public class BulletContoller : MonoBehaviour { 

Rigidbody rb; 
public float bulletForce; 
bool firstTime = false; 
Vector3 direction; 

// Use this for initialization 
void Start() { 
    rb = GetComponent<Rigidbody>(); 
} 


public void SetDirection (Vector3 dir) { 
    direction = dir; 
    firstTime = true; 
} 

void OnCollisionEnter (Collision col) { 
    //code for when bullet hits something 
    if (col.gameObject.name == "Target") { 
     this.gameObject.name = "Hit"; 
    } 
} 

void FixedUpdate() { 
    if (firstTime) { 
     rb.AddForce (direction * bulletForce); 
     firstTime = false; 
    } 
} 
} 
+0

커서 위치가 잘못되었다고 생각됩니다. 그것이 맞는지 확인 했습니까? – Bart

+0

어떻게하면됩니까? – ProgrammingLife

답변

1

당신은 잘 할 수있다, 그것은 될 수있는 컨트롤러에서 캡슐 문제는,이 작업을 수행 :

  1. 플레이어글 머리 기호라는 이름의 2 층을 만듭니다.
  2. PlayerController를 플레이어에 배치합니다.
  3. 레이어에 글 머리 기호를 넣으십시오 글 머리 기호.
  4. 편집으로 이동 -> 프로젝트 설정 -> 물리레이어 충돌 행렬에 있는지 확인하십시오 플레이어 계층과 서로 충돌하지 않는 글 머리 기호 층.
+0

이제 지원됩니다. 도와 주셔서 감사합니다. 전에는 몰랐어. – ProgrammingLife

관련 문제