Skip to content

Commit

Permalink
Camera: Lerp Speed Property (#1)
Browse files Browse the repository at this point in the history
* ignore idea dir

* add lerp speed to camera object and set default to previously used value
  • Loading branch information
aidencompsci authored Aug 4, 2024
1 parent 21c7353 commit e1fdcc9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# Dependency directories (remove the comment below to include it)
# vendor/

# IDE/Editor directories
.idea/*

# Go workspace file
go.work
examples/.DS_Store
Expand Down
6 changes: 4 additions & 2 deletions camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type Camera struct {
ZoomFactor float64

// Interpolate camera movement
Lerp bool
Lerp bool
LerpSpeed float64

// Camera shake options
ShakeOptions CameraShakeOptions
Expand All @@ -34,6 +35,7 @@ func NewCamera(lookAtX, lookAtY, w, h float64) *Camera {
c := &Camera{
ZoomFactor: 0,
Lerp: false,
LerpSpeed: 0.1,
ShakeOptions: DefaultCameraShakeOptions(),
// private
w: w,
Expand All @@ -59,7 +61,7 @@ func NewCamera(lookAtX, lookAtY, w, h float64) *Camera {
func (cam *Camera) LookAt(targetX, targetY float64) {
target := vec2{targetX, targetY}
if cam.Lerp {
cam.tempTarget = cam.tempTarget.Lerp(target, 0.1)
cam.tempTarget = cam.tempTarget.Lerp(target, cam.LerpSpeed)
cam.topLeft = cam.tempTarget
} else {
cam.topLeft = target
Expand Down

0 comments on commit e1fdcc9

Please sign in to comment.