Adding vehicles to Shootergame with custom gravity
I'm running a custom gravity mod based on 4.10 that overrides CharacterMovementComponent. I've built ShooterGame on top of that and am running around now quite nicely with custom gravity.
I'm having troubles implementing vehicles. I've got my own AVehicle class that inherits from APawn and a UVehicleMovementComponent that inherits from UCharacterMovementComponent. The reason I inherited from there is that the gravity code is in there. I've not actually changed anything in the movement component. It's "as is".
Currently I've managed to possess the vehicle, attach my character to it and that's it. I can also unpossess it and the same instance of character jumps out (with health, ammo and all). But I can't make the vehicle move. The vehicle gets the movement component in its constructor with objectinitializer. I've bound input to move forward axis. When I possess the vehicle with a controller, I set the movement mode to MOVE_Flying for the VehicleMovementComponent so that I can move it without checking surfaces or whatnot (it's gonna be a rocket pod anyway), but the bugger just sits still. I've debugged that it calls my MoveForward() function after I mount it (but it actually calls it every tick even when there is no input - is this a feature?). I've tried everything: AddForce, Velocity += 100, AddMovementInput etc. Nothing works. It won't budge. Currently it looks like a standard copy-paste:
I've got the SkeletalMesh set to physics enabled (it's just the SkeletalCube from the engine folders with a socket where the character gets stuck into) in c++ and double checked in the editor. I've been keeping the vehicle as simple as possible, so it has only a skeletalmesh and a movement component.
I'm suspecting the problem is not my MoveForward function at all, but somewhere else. I haven't made any vehicles before, so I might be missing something really obvious.
After stepping through the code I noticed that AddMovementInput() (AMI) makes a call to GetMovementComponent. The interesting thing is that when AMI is called inside a character class it eventually calls ACharacter::GetMovementComponent() whereas if AMI is called from a pawn class it instead calls APawn::GetMovementComponent. Rather than basing your vehicle class on Pawn, another option would be to base the vehicle class on Character and include a Child Actor component and some kind of triggering volume (sphere, box, etc.). When the player overlaps the trigger volume you set the child actor component to the Player to attach them to the vehicle. Hopefully this helps get the vehicle moving with the player properly.
answered Feb 03 '16 at 08:47 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here