16
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 18 Jul 2023
16 points (100.0% liked)
Godot
5884 readers
1 users here now
Welcome to the programming.dev Godot community!
This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.
Make sure to follow the Godot CoC while chatting
We have a matrix room that can be used for chatting with other members of the community here
Links
Other Communities
- !inat@programming.dev
- !play_my_game@programming.dev
- !destroy_my_game@programming.dev
- !voxel_dev@programming.dev
- !roguelikedev@programming.dev
- !game_design@programming.dev
- !gamedev@programming.dev
Rules
- Posts need to be in english
- Posts with explicit content must be tagged with nsfw
- We do not condone harassment inside the community as well as trolling or equivalent behaviour
- Do not post illegal materials or post things encouraging actions such as pirating games
We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent
Wormhole
Credits
- The icon is a modified version of the official godot engine logo (changing the colors to a gradient and black background)
- The banner is from Godot Design
founded 1 year ago
MODERATORS
Not at all. I don't have wall clipping support set up yet at all! It's a lot more simplistic. I've handled wall clipping in a similar camera system before using a SpringArm, but I don't think that will work here.
What I do here is I have one object that follows just the camera's y rotation, and I use that to get a forward vector using
-object.basis.z.normalized()
and I set a target position atplayer_pos + -forward * FOLLOW_DISTANCE + Vector3.UP * FOLLOW_HEIGHT
and lerp to there. That handles moving with the player forward and backwards.Then in the player code, I read the stick input into
Vector3(x, 0, y)
and then rotate it based on the camera's y rotation to put it into screen coordinates. Then I multiply byMOVE_SPD
and set velocity.x & .z to the x and z of the product. This makes the player move forward and back with relation to the camera's forward and back.However, you move left and right based on the tangent of a circle around the camera because back in the camera code, I have a look_at which causes the camera to turn as the player moves right/left relative to it, causing circular motion.
Beyond that, there are some simple tweaks like a timer that runs before setting a boolean to cause it to rotate back behind the player or only moving if the player is outside of the follow distance. Things like that.
It's pretty tightly coupled, which isn't great from a code perspective, but it's also unlikely to fundamentally change. If that were to happen, I'd probably want to totally rewrite the system anyway.
I just found it online somewhere years ago lol. Probably opengameart? I no longer have the original source, but it's pretty good for testing:
That sounds a bit fiddly just from reading it but I'm sure it makes totally sense in code. Now that you mentioned it, yes adapting the players forward based on camera view is something I totally forgot here.