Bullet has wrong direction on client
Hey folks, I´m currently making a MULTIPLAYER arena game (a bit like head scoccer), where you shoot and aim by clicking on a point at the screen. The bullet will then move towards that point. This is done by raycasting. The direction is calculated by subtracting the click position from the current position. Unfortunately, the direction on the client is always wrong. The bullet spawns and moves in a complete different direction. PS: Bullet has Network Identity component with Server only checked PS. Bullet has Network Transform with Sync rate of 1 and Rigidbody3D sync
Thanks a lot! Love your help!
void Start(){ Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100f); Vector3 f = new Vector3(hit.point.x, hit.point.y, 0f); //y-value is 0f, because the game is 2D although made in Unity3D direction = (f - transform.position).normalized; } void Update(){ rb.velocity = new Vector3(direction.x, direction.y, direction.z) * speed * Time.deltaTime; }
Please format your code by adding 5 spaces before each line
Your answer
Follow this Question
Related Questions
Looking for tips on identifying reason behind random client disconnects 0 Answers
Networking functions work fine on player object, but not other objects 0 Answers
non-player object can't execute's "[Command]"'s attributes 0 Answers
Best way to learn Networking in general 0 Answers
LAN Auto find server/host 0 Answers