#Cam Tilt

1 messages · Page 1 of 1 (latest)

glad osprey
#

I am trying to make the camera tilt to the side a bit when you press A or D. I had something but it made the normal camera movement very weird.

crude python
#

step 1) something that will be especially useful for this, but is good practice in general, is to make your camera's up-down and left-right rotations work on different objects. you've already got the right idea making the Camera3d the parent of a "Head" node, mine here is called "PlayerEyeLocation" but I imagine it's basically the same deal. so instead of rotating the camera directly, you rotate the twist pivot along the Y axis and the pitch pivot along the X axis.

#

step 2) assuming you want a subtle, smooth camera tilt, you want a way of shifting between "camera is z-rotated by -[tilt_max] degrees" and "camera is z-rotated by +[tilt_max] degrees". your player character doesn't accelerate and deccelerate while walking so it can't be tied to that, so i'd suggest a semi-framerate-independent lerp? bit quick and dirty but it should work. (this all should go in the physics process BTW, and you have to initialise a "current tilt" variable at the top of the script)

var desired_tilt = input_dir.x * max_tilt_angle
var base_lerp_rate = 10.0
var semi_indep_lerp_rate = clamp(base_lerp_rate *delta,0.001,1.0)
current_tilt = lerp(current_tilt,desired_tilt,semi_indep_lerp_rate)
%Camera3D.rotation.z = current_tilt```
glad osprey
#

Okay thanks. I will try it!