Little side scroller project I’ve been playing around with today while I should be working
I don’t have any actual character models, so for now I’m just using two cylinders, one encapsulates the capsule component and simulates the player’s body, the other is a smaller one simulating a weapon. As you move your cursor around, the weapon rotates around to face the mouse position, left click fires. Works well in single player.
I’m having difficulty getting the gun’s rotation to replicate though. It seems the “Replicate Movement” under a character’s defaults tab only handles as much as the actor’s location and rotation, ignoring the specific components. Here is my blueprint to handle the gun rotation:
So I get the controller, get the mouse position, use some shoddy math to adjust it so it uses the center of the screen instead of the top left corner, do some other questionable things with the rotation to get it right (not pretty, this was a trial and error effort) and finally get the new rotation.
My poor calculations aside, I get the new rotation and call UpdateGunRotation
Which is a custom multicast event, taking the rotation and applying it to the component.
A side note, for some reason the text on the event node in the last screenshot didn’t update, it’s set to “Multicast”, not “Run on server”.
With this implementation, each client only sees their own gun move.
So, my questions:
- How can I properly replicate the movement of a component? If I need to make the weapon its own actor (with replicated movement) and attach it to the player, I can do that as well but I will probably encounter this problem somewhere in the future as well so it would be good to know.
- Slightly off topic, is there a better way to handle this than using an event tick? I always like to avoid using it when possible, but I don’t see a way around it here.
- When I run multiplayer, my error log gets flooded with “Accessed None ‘CallFunc_GetController_ReturnValue’ from node Construction Script in blueprint Character”, “Accessed None ‘CallFunc_CastToPlayerController_ReturnValue’ from node Construction Script in blueprint Character”. I don’t think this is related to my replication problem… seems like the editor just doesn’t like trying to get the controller when I have multiple clients open on the same machine, but I’m not sure. Any thoughts on what might cause that error?
Edit: Due to the lack of response, I ended up using another actor for the weapon and attaching it, worked fine.