#Making networked object go to mouse on multiplayer problem
1 messages · Page 1 of 1 (latest)
I use client Rpc to instanitate, how would I do that?
#🤝help-archive message
CmdShootRay(direction, 2);
[Command]
void CmdShootRay(Vector3 _hitDir, int _bulletType)
{
RpcFireWeapon(_hitDir,_bulletType);
}
[ClientRpc]
void RpcFireWeapon(Vector3 _hitDir, int _bulletType)
{
}
@olive kite
depends, use that method of passing data for whatever you want
But could that make the projectile go to a certain spot after the thing was already spawned?
Because the object already spawns at the same spot for both clients
However I want the Object to also move towards the mouse, specifically the player who spawned it
And not the other mouse, which is the problem
Because the spawned object already has a script that makes it move to the mouse
Send end position.
then when its spawned.
set the sync var endPosition
or regular variable
[ClientRpc]
void RpcFireWeapon(Vector3 _startPosition, Vector3 _endPosition)
{
}
GameObject obj = instantiate blah blah
obj.GetCompoent blah blah endPosition = _endposition
Im off to bed, good luck 💪
Sorry I'm new to this stuff, what would I do with the endPosition?
Would I send it over to the other script?
ive no idea what your trying to do now, completely lost
Q_Q
Okay, so the Object i'm spawning has the following script:
void Start()
{
mainCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
rb = GetComponent<Rigidbody2D>();
mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition);
Vector3 direction = mousePos - transform.position;
Vector3 rotation = transform.position - mousePos;
rb.velocity = new Vector2(direction.x, direction.y).normalized * force;
float rot = Mathf.Atan2(rotation.y, rotation.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0,0, rot * 90); //rotate bullet 90 degrees if upright
}
This is a fireball that goes to the mouse
It works-
However
With two players, a problem occurs
I use this to spawn the fireball:
[Command]
void shootfireball()
{
RpcShootfireball();
}
[ClientRpc]
void RpcShootfireball()
{
GameObject netfireball = Instantiate(bullet, bulletTransform.position, Quaternion.identity);
canFire = false;
}
So it makes one fireball on both sides
However each fireball goes to each players individual mouse
When the fireballs should both ideally go to the mouse of the player who spawned it
Does that make it more clear?