18-02-2019, Saat: 17:11
Elimizde playerlar var ve top objemiz var . Bu playerlardan biri topa dokunursa topa mouse'un olduğu yöne doğru kuvvet uygulanacak.Main clientte yani odanın kurulduğu playerda kuvvet uygulanırken 2. bağlanan oyuncuda kuvvet uygulanmıyor.mouse koordinatları 0,0,0'da hiç değişmeden duruyor.
kodum şu şekilde :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
public class oyuncukontrol : Photon.PunBehaviour
{
public float hız = 3.5f;
public int vur = 0;
public Vector3 targetPos;
Vector3 lookattarget;
public Rigidbody rb;
void Start()
{
rb = GameObject.FindGameObjectWithTag("TOP").GetComponent<Rigidbody>();
}
void Update()
{
if (photonView.isMine)
{
var movement = Vector3.zero;
movement.x = Input.GetAxis("Horizontal") * hız;
movement.z = Input.GetAxis("Vertical") * hız;
movement = Vector3.ClampMagnitude(movement, hız);
movement *= Time.deltaTime;
transform.Translate(movement);
}
else { }
}
private void OnCollisionStay(Collision collision)
{
if (photonView.isMine)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (collision.gameObject.tag == "TOP")
{
if (vur == 0)
{
if (Physics.Raycast(ray, out hit, 100))
{
targetPos = hit.point;
lookattarget = new Vector3(targetPos.x - transform.position.x, targetPos.y - transform.position.y, targetPos.z - transform.position.z);
rb.AddForce(lookattarget * 20);
rb.AddForce(Vector3.up * 40);
vur = 0;
}
}
}
}
}
}
Sıkıntılı olan kısım targetpos değişmiyor.
kodum şu şekilde :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
public class oyuncukontrol : Photon.PunBehaviour
{
public float hız = 3.5f;
public int vur = 0;
public Vector3 targetPos;
Vector3 lookattarget;
public Rigidbody rb;
void Start()
{
rb = GameObject.FindGameObjectWithTag("TOP").GetComponent<Rigidbody>();
}
void Update()
{
if (photonView.isMine)
{
var movement = Vector3.zero;
movement.x = Input.GetAxis("Horizontal") * hız;
movement.z = Input.GetAxis("Vertical") * hız;
movement = Vector3.ClampMagnitude(movement, hız);
movement *= Time.deltaTime;
transform.Translate(movement);
}
else { }
}
private void OnCollisionStay(Collision collision)
{
if (photonView.isMine)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (collision.gameObject.tag == "TOP")
{
if (vur == 0)
{
if (Physics.Raycast(ray, out hit, 100))
{
targetPos = hit.point;
lookattarget = new Vector3(targetPos.x - transform.position.x, targetPos.y - transform.position.y, targetPos.z - transform.position.z);
rb.AddForce(lookattarget * 20);
rb.AddForce(Vector3.up * 40);
vur = 0;
}
}
}
}
}
}
Sıkıntılı olan kısım targetpos değişmiyor.