I’m doing a small mockup of a runner style game as a proof of concept.
I’m using a custom controller that utilizes a rigidbody, and at the moment the character only needs to run forward and side to side, so that’s what it does.
So I have it running, I have a camera smoothly following it, but I’d like to offset it by a certain amount on the z-axis, controlled by the player, so that there’s a bit of give in the character’s position for the player to move forward and backward, allowing them to time when they go past obstacles and the like.
I thought of having a main collider that handles all the normal movement and only collides with guiding geometry, then having an empty gameObject holding the character and related bits that I could offset, letting the character have it’s own collider that could react to obstacles.
This approach obviously wouldn’t work, since the timing between the character and it’s parent would be off in regards to things like slopes.
I haven’t really had much cause to think about this issue until now, so I’m slightly mystified as to how to go about it. Does anyone have any ideas as to the general direction I should be headed to make this work?
Thanks for any help and advice.
Also, my topic title is terrible and vague. Not sure what to put that’s short and concise, yet accurate and descriptive. Feel free to suggest a change.
Aye, something like that.
The character moves at a fixed rate in a direction I set, unaffected by the player, with the camera following. The only movement they can affect is lateral movement on the local x-axis.
I want the player to be able to adjust the character’s movement in all directions on the ground, within a certain limit (so they can’t go off path or too far ahead or back) without touching the character’s actual speed or overall movement going forward.
If you take an old Shmup like R-Type, and pretend it’s a top down view, that’s kind of close.
Only, all the complications of a Rigidbody and the requirement to actually move forward.
I’d been looking into it, since I’d eventually need to move everything back to origin after a while anyway, but my initial forays into this area have been rather troubling when using a Rigidbody.
If I can’t come up with any other solution then I’ll see if I can force it to work, but I’d really rather find a different solution.
I have a few other ideas to try, but I really have no idea if they’ll work or how hard they’ll be to implement, so I came here to see if anyone had done this before or if there was something obvious I was missing.
You can actually combine Transform.position and Rigidbody movement together. I would set the characters forward movement every frame with transform.position, and then allow the characters local movement to be handled with the ridgidbody.
One of the things I was considering was using the normal Rigidbody movement as I am now, but allowing the position to be offset with Rigidbody.MovePosition, so that seems similar to your suggestion.
If I handle the forward movement with Transform.position while using a Rigidbody, don’t I run the risk of poor interactions with any other Rigidbody objects? And how would it handle using physics to ascend slopes?
Or do you propose only setting the z-axis movement, while letting x and y be handled by the Rigidbody?