Alternate approach using move

EDIT: While my below solution hasn’t seemed to “bite” me, I will note that you probably want to stick with the lectures unless you’re comfortable with C++ and refactoring. There’s a lot of tiny refactors that you need to make in upcoming lectures, and those can get challenging unless you understand the way this code needs to be refactored to match the changes in the lectures.

I had an alternate way of generating the move struct. I’m not sure if it will bite me later, but I figured I’d share it for now (maybe someone else will see something I don’t?).

I added an FGoKartMove private variable to the AGoKart class and removed the individual Throttle and SteeringThrow variables. This is now used everywhere inplace of Throttle and SteeringThrow. Within Tick, as part of the HasAuthority() if statement, I added an else if to check if we’re the client and send the move to the server if so:

	if (HasAuthority())
	{
		ServerState.Transform = GetActorTransform();
		ServerState.Velocity = Velocity;
		// TODO: update last move
	}
	else if (IsLocallyControlled())
	{
		Server_SendMove(Move);
	}

As far as I can tell, things seem work properly with this approach and I prefer it since it saves the redundancy of having separate movement variables that are then just copied into this struct each tick anyway. It may bite me in future lectures, but I’ll come back and add a big warning at the top of this post if it does.

Here’s a link to this entire change on my github repo: Refactoring movement to structs and adding ServerState struct · pres2300/KrazyKartsUE5@9609cfe · GitHub

1 Like

Privacy & Terms