Ajuda com Raycast position de Prefabs (Photon + unity)
2 participantes
Página 1 de 1
Ajuda com Raycast position de Prefabs (Photon + unity)
Instancio o player no prefab e vejo corretamente, ando e pulo tranquilo, porém quando aciono o raycast ele parte de uma posição errada e direção certa. script linkado a camera.
- Código:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shoot : MonoBehaviour
{
int damage = 100;
int armaNaMao;
public Arma[] scptArma;
public AudioSource emissorSom;
public GameObject objetoRecuo;
GameObject balaProjetil;
string balaHits;
Vector3 miraAberta; // x = 0.016. y = 0.8239999, z = 0.113
Vector3 miraFechada;
NetworkCharacter nC;
public Camera cam;
PhotonView getPV;
GameObject balaTraj;
bool atirou = false;
public PhotonView essePV;
GameObject canoDaArma;
Vector3 canoPos;
[Header("Mira Aberta e Laser")]
public bool ativarLaser = false;
public Color corLaser = Color.red;
public bool AtivarMiraComum = true;
[HideInInspector]
public LineRenderer linhaDoLaser;
public Material MaterialLasers;
GameObject luzColisao;
// Start is called before the first frame update
void Start()
{
miraAberta = gameObject.transform.parent.Find("Camera").localPosition;
miraFechada = new Vector3(0.1559f, 0.763f, 0.2838f);
armaNaMao = 0;
//balaProjetil = "" + scptArma[armaNaMao].balaProjetil;
// Mira Laser
luzColisao = new GameObject ();
luzColisao.AddComponent<Light> ();
luzColisao.GetComponent<Light> ().intensity = 8;
luzColisao.GetComponent<Light> ().bounceIntensity = 8;
luzColisao.GetComponent<Light> ().range = 0.2f;
luzColisao.GetComponent<Light> ().color = Color.red;
LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer> ();
lineRenderer.material = MaterialLasers;
// lineRenderer.SetColors(Color.white, Color.white);
lineRenderer.startColor = Color.white;
lineRenderer.endColor = Color.white;
// lineRenderer.SetWidth (0.015f, 0.05f);
lineRenderer.startWidth = 0.015f;
lineRenderer.endWidth = 0.05f;
lineRenderer.positionCount = 2;
linhaDoLaser = GetComponent<LineRenderer> ();
}
void Update()
{
canoPos = new Vector3(scptArma[armaNaMao].canoDaArma.transform.position.x, scptArma[armaNaMao].canoDaArma.transform.position.y, scptArma[armaNaMao].canoDaArma.transform.position.z);
if(Input.GetButton("Mirar")){
gameObject.transform.parent.Find("Camera").transform.localPosition = miraFechada;
} else {
gameObject.transform.parent.Find("Camera").transform.localPosition = miraAberta;
}
if(Input.GetButton("Fire1") && scptArma[armaNaMao].modoDeTiro == "Automatico"){
//essePV.RPC("Atirar", PhotonTargets.All, scptArma[armaNaMao].canoDaArma.transform.position, transform.rotation, armaNaMao);
//Atirar(canoPos, scptArma[armaNaMao].canoDaArma.transform.rotation, armaNaMao);
Disparar(canoPos, scptArma[armaNaMao].canoDaArma.transform.rotation);
//getPV = GetComponent<PhotonView>();
//Vector3 pos = myPosition();
//ServerHandler.ServerManager.RPC("projetilEmRede", PhotonTargets.All, pos, transform.rotation, 5, getPV.viewID);
}
if(scptArma[armaNaMao].linhaDoLaser.enabled == true){
linhaDoLaser.material.SetColor ("_TintColor", scptArma[armaNaMao].corLaser);
luzColisao.SetActive (true);
Vector3 PontoFinalDoLaser = transform.position + (transform.forward * 500);
RaycastHit hitDoLaser;
if (Physics.Raycast (transform.position, transform.forward, out hitDoLaser, 500)) {
linhaDoLaser.SetPosition (0, transform.position);
linhaDoLaser.SetPosition (1, hitDoLaser.point);
float distancia = Vector3.Distance (transform.position, hitDoLaser.point) - 0.03f;
luzColisao.transform.position = transform.position + transform.forward * distancia;
} else {
linhaDoLaser.SetPosition (0, transform.position);
linhaDoLaser.SetPosition (1, PontoFinalDoLaser);
luzColisao.transform.position = PontoFinalDoLaser;
}
}
}
IEnumerator destruirBala(GameObject bala){
if(atirou == true){
atirou = false;
yield return new WaitForSeconds(2);
PhotonNetwork.Destroy(bala);
}
atirou = false;
}
void Disparar(Vector3 pos, Quaternion dir){
Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
RaycastHit hitInfo;
//GameObject balaTraj = (GameObject) PhotonNetwork.Instantiate("Projetil", pos, dir, 0) as GameObject;
//balaTraj.transform.position = pos;
//atirou = true;
//StartCoroutine(destruirBala(balaTraj));
if(Physics.Raycast(ray, out hitInfo)){
Debug.Log("Alvo alvejado: " + hitInfo.collider.name);
}
}
void Atirar(Vector3 pos, Quaternion dir, int armaUsada){
int damage = scptArma[armaNaMao].potenciaDaArma;
objetoRecuo.GetComponent<Animation>().Play("fireRecuo");
scptArma[armaNaMao].partFogo.Play();
//emissorSom.clip = scptArma[armaNaMao].somDoTiro;
//emissorSom.PlayOneShot (emissorSom.clip);
GameObject balaTraj = (GameObject) PhotonNetwork.Instantiate("Projetil", pos, dir, 0) as GameObject;
// cord cano da arman = -1083.283, 9.900113, -1163.831
//balaTraj.transform.SetParent(scptArma[armaUsada].canoDaArma.transform);
//pos = new Vector3(0.7724708f, 3.484503f, 3.912991f);
Vector3 posCano = pos;
balaTraj.transform.position = pos;
atirou = true;
StartCoroutine(destruirBala(balaTraj));
//balaTraj.transform.rotation = dir;
//PhotonNetwork.Destroy(balaTraj);
RaycastHit pontoDeColisao;
if(Physics.Raycast(transform.position, transform.forward, out pontoDeColisao)){
if(pontoDeColisao.collider.gameObject.GetComponent<Health>()){// && pontoDeColisao.gameObject.tag == enemyTeam){
GameObject balaColidir = Instantiate(balaTraj, pontoDeColisao.point + (pontoDeColisao.normal * 0.01f), Quaternion.identity);
Destroy(balaColidir, 5f);
PhotonView pv;
pv = pontoDeColisao.collider.gameObject.GetComponent<PhotonView>();
pv.RPC("receberDano", PhotonTargets.All, damage);
Debug.Log("Acertou inimigo: " + pontoDeColisao.transform.name);
} else {}
} else {
print("Nenhuma Colisão Fisica");
}
}
}
KlaytonOCara- Iniciante
- PONTOS : 1707
REPUTAÇÃO : 0
Respeito as regras :
Re: Ajuda com Raycast position de Prefabs (Photon + unity)
voce conseguiu resolver??
se sim me ajuda ai to tendo esse mesmo problema
[ltr] TRANSLATE with x
English
[/ltr]
[ltr]
var LanguageMenu; var LanguageMenu_keys=["ar","bg","ca","zh-CHS","zh-CHT","cs","da","nl","en","et","fi","fr","de","el","ht","he","hi","mww","hu","id","it","ja","tlh","ko","lv","lt","ms","mt","no","fa","pl","pt","ro","ru","sk","sl","es","sv","th","tr","uk","ur","vi","cy"]; var LanguageMenu_values=["Arabic","Bulgarian","Catalan","Chinese Simplified","Chinese Traditional","Czech","Danish","Dutch","English","Estonian","Finnish","French","German","Greek","Haitian Creole","Hebrew","Hindi","Hmong Daw","Hungarian","Indonesian","Italian","Japanese","Klingon","Korean","Latvian","Lithuanian","Malay","Maltese","Norwegian","Persian","Polish","Portuguese","Romanian","Russian","Slovak","Slovenian","Spanish","Swedish","Thai","Turkish","Ukrainian","Urdu","Vietnamese","Welsh"]; var LanguageMenu_callback=function(){ }; var LanguageMenu_popupid='__LanguageMenu_popup';
[url=javascript:Microsoft.Translator.FloaterShowEmbed()] [/url] [url=javascript:Microsoft.Translator.FloaterShowSharePanel()] [/url]
TRANSLATE with
COPY THE URL BELOW
[url=javascript:Microsoft.Translator.FloaterOnShareBackClick()] Back[/url]
EMBED THE SNIPPET BELOW IN YOUR SITE
Enable collaborative features and customize widget: Bing Webmaster Portal
[url=javascript:Microsoft.Translator.FloaterOnEmbedBackClick()]Back[/url]
var intervalId = setInterval(function () { if (MtPopUpList) { LanguageMenu = new MtPopUpList(); var langMenu = document.getElementById(LanguageMenu_popupid); var origLangDiv = document.createElement("div"); origLangDiv.id = "OriginalLanguageDiv"; origLangDiv.innerHTML = "<span id='OriginalTextSpan'>ORIGINAL: </span><span id='OriginalLanguageSpan'></span>"; langMenu.appendChild(origLangDiv); LanguageMenu.Init('LanguageMenu', LanguageMenu_keys, LanguageMenu_values, LanguageMenu_callback, LanguageMenu_popupid); window["LanguageMenu"] = LanguageMenu; clearInterval(intervalId); } }, 1); [/ltr]
se sim me ajuda ai to tendo esse mesmo problema
[ltr] TRANSLATE with x
English
[/ltr]
[url=#ar]Arabic[/url] | [url=#he]Hebrew[/url] | [url=#pl]Polish[/url] |
[url=#bg]Bulgarian[/url] | [url=#hi]Hindi[/url] | [url=#pt]Portuguese[/url] |
[url=#ca]Catalan[/url] | [url=#mww]Hmong Daw[/url] | [url=#ro]Romanian[/url] |
[url=#zh-CHS]Chinese Simplified[/url] | [url=#hu]Hungarian[/url] | [url=#ru]Russian[/url] |
[url=#zh-CHT]Chinese Traditional[/url] | [url=#id]Indonesian[/url] | [url=#sk]Slovak[/url] |
[url=#cs]Czech[/url] | [url=#it]Italian[/url] | [url=#sl]Slovenian[/url] |
[url=#da]Danish[/url] | [url=#ja]Japanese[/url] | [url=#es]Spanish[/url] |
[url=#nl]Dutch[/url] | [url=#tlh]Klingon[/url] | [url=#sv]Swedish[/url] |
[url=#en]English[/url] | [url=#ko]Korean[/url] | [url=#th]Thai[/url] |
[url=#et]Estonian[/url] | [url=#lv]Latvian[/url] | [url=#tr]Turkish[/url] |
[url=#fi]Finnish[/url] | [url=#lt]Lithuanian[/url] | [url=#uk]Ukrainian[/url] |
[url=#fr]French[/url] | [url=#ms]Malay[/url] | [url=#ur]Urdu[/url] |
[url=#de]German[/url] | [url=#mt]Maltese[/url] | [url=#vi]Vietnamese[/url] |
[url=#el]Greek[/url] | [url=#no]Norwegian[/url] | [url=#cy]Welsh[/url] |
[url=#ht]Haitian Creole[/url] | [url=#fa]Persian[/url] |
var LanguageMenu; var LanguageMenu_keys=["ar","bg","ca","zh-CHS","zh-CHT","cs","da","nl","en","et","fi","fr","de","el","ht","he","hi","mww","hu","id","it","ja","tlh","ko","lv","lt","ms","mt","no","fa","pl","pt","ro","ru","sk","sl","es","sv","th","tr","uk","ur","vi","cy"]; var LanguageMenu_values=["Arabic","Bulgarian","Catalan","Chinese Simplified","Chinese Traditional","Czech","Danish","Dutch","English","Estonian","Finnish","French","German","Greek","Haitian Creole","Hebrew","Hindi","Hmong Daw","Hungarian","Indonesian","Italian","Japanese","Klingon","Korean","Latvian","Lithuanian","Malay","Maltese","Norwegian","Persian","Polish","Portuguese","Romanian","Russian","Slovak","Slovenian","Spanish","Swedish","Thai","Turkish","Ukrainian","Urdu","Vietnamese","Welsh"]; var LanguageMenu_callback=function(){ }; var LanguageMenu_popupid='__LanguageMenu_popup';
[url=javascript:Microsoft.Translator.FloaterShowEmbed()] [/url] [url=javascript:Microsoft.Translator.FloaterShowSharePanel()] [/url]
TRANSLATE with
COPY THE URL BELOW
[url=javascript:Microsoft.Translator.FloaterOnShareBackClick()] Back[/url]
EMBED THE SNIPPET BELOW IN YOUR SITE
Enable collaborative features and customize widget: Bing Webmaster Portal
[url=javascript:Microsoft.Translator.FloaterOnEmbedBackClick()]Back[/url]
var intervalId = setInterval(function () { if (MtPopUpList) { LanguageMenu = new MtPopUpList(); var langMenu = document.getElementById(LanguageMenu_popupid); var origLangDiv = document.createElement("div"); origLangDiv.id = "OriginalLanguageDiv"; origLangDiv.innerHTML = "<span id='OriginalTextSpan'>ORIGINAL: </span><span id='OriginalLanguageSpan'></span>"; langMenu.appendChild(origLangDiv); LanguageMenu.Init('LanguageMenu', LanguageMenu_keys, LanguageMenu_values, LanguageMenu_callback, LanguageMenu_popupid); window["LanguageMenu"] = LanguageMenu; clearInterval(intervalId); } }, 1); [/ltr]
junio132sj- Iniciante
- PONTOS : 1127
REPUTAÇÃO : 0
Respeito as regras :
Tópicos semelhantes
» Unity 2018.2 -Ajuda com sistema de SpawnPoint e respawn com Photon Bolt
» [ERRO DO PHOTON] Script do Photon com a unity
» AJUDA NOS PREFABS
» [AJUDA] transform.position
» Erro Transfom.Position Unity
» [ERRO DO PHOTON] Script do Photon com a unity
» AJUDA NOS PREFABS
» [AJUDA] transform.position
» Erro Transfom.Position Unity
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos