- Home /
Photon instantiate and addforce to arrow
I have a third person character, with a child object calle ArrowSpawn. It holds the position of where the arrow should spawn when instantiated. Currently its working fine in singleplayer, but in multiplayer it doesnt work. The arrow is spawned twice, one of the arrows disappear right away and the other falls to the ground.
This is the code i use:
[RPC]
public void LooseArrow(){
GameObject arrowclone; // the prefab of the arrow
arrowclone = PhotonNetwork.Instantiate (transform.GetComponent<tpAnimator>()
.arrow.name, GetComponent<tpAnimator>().arrowPosition.transform.position, GetComponent<tpAnimator>().
arrowPosition.transform.rotation , 0); // ArrowPosition is the gameobject holding the spawn location and rotation, its located at the right hand bone.
Vector3 direction = (GetComponent<CrosshairAim>().test - GetComponent<tpAnimator>().arrowPosition.transform.position).normalized; // sets the direction from spawnpoint towards crosshair.
arrowclone.GetComponent<Rigidbody>().AddForce (direction * 300);
}
I think your problem is that you are getting values using GetComponent in your RPC method. Ins$$anonymous$$d, pass those values to your RPC method when you call it. It's been a while since I did any networking though, so I might be wrong. (Your method is also really hard to read like this, so even if that's not actually the problem it's probably a good idea to do anyway).
hm, i tried to pass in the values like you said but no change, thanks for reply tho. Formatted the code a little in my script so its a little easier to read, will update here when i get home tomorrow.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Jump Force gets added up with repeated input and causes character to fly off 0 Answers
Random instantiate at same frame with each instantiate having unique random direction 1 Answer
Increase force/size the longer input has been held down. 2 Answers
Projectile not moving properly in top down 2d shooter 2 Answers