RayLib Challenge Part 7 - Building a Player Tracking Camera

  Рет қаралды 2,160

Kea Sigma Delta

Kea Sigma Delta

Күн бұрын

Last time, we got displaying the 2D world working, but there was a big problem. The camera wasn't following scarfy (the player) wherever he went. Today, we add player tracking code to the 2D camera.
Click the following link for a summary (and to download the code):
keasigmadelta.com/blog/raylib...

Пікірлер: 11
@bonehelm
@bonehelm Жыл бұрын
The PID controller method seems a bit over engineered. Not sure if it's more accurate/stable or what. But a much easier method that works 99% of the time is to just lerp the camera towards it's target. In the header "raymath.h" there's a "Vector2Lerp" function that you could use. Like this: this->position = Vector2Lerp(this->position, target->position, smoothFactor), where smoothFactor is a float between 0 and 1 but something around 0.15 should be good.
@KeaSigmaDelta
@KeaSigmaDelta Жыл бұрын
Thanks for the suggestion. You're right that using lerp would be nice and simple. I chose PID simply because I felt like it, and not because of any known benefits. Theoretically, it should get the camera centred faster, but at risk of overshoot and oscillations.
@dylanlamb2396
@dylanlamb2396 9 ай бұрын
Thank you so much for this. It's not quite what I've been looking for, but it works SO MUCH BETTER than what I've been trying to do. Cheers!
@jadenh_gamedev
@jadenh_gamedev Жыл бұрын
Nice work. I always find hard coding cameras a pain to do. I've done it in the past with other libraries but my collision etc. was off. Hopefully raylib provides the tools for me to do this bug free.
@KeaSigmaDelta
@KeaSigmaDelta Жыл бұрын
Thanks. RayLib has collision detection functions which could help you, but you'll have to stitch it all together, just like I did with the 2D camera tracking.
@jadenh_gamedev
@jadenh_gamedev Жыл бұрын
@@KeaSigmaDelta thanks for replying, right now I'm building GUI tools for raylib. Hopefully the built in camera is good enough for my needs with some hard coding.
@KeaSigmaDelta
@KeaSigmaDelta Жыл бұрын
@@jadenh_gamedev I wish you all the best with your project.
@youne1982
@youne1982 Жыл бұрын
Plz i have a probleme when i compile my code a warning says thta the map is empty maybe the probleme is to save tmx file including tsx file i made How to save a tmx file after using layers
@KeaSigmaDelta
@KeaSigmaDelta Жыл бұрын
I'd need more information to know what's going wrong. What is the exact warning message? And when does it appear (e.g., is it a compiler warning, or one that appears when running the compiled code)? I'm guessing that your tmx file saving question has nothing to do with your code, since you save it in Tiled.
@youne1982
@youne1982 Жыл бұрын
@@KeaSigmaDelta 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,41,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,41,41,41,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,41,41,41,41,41,521,521,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, 69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,81 167,131,179,131,131,179,131,131,131,131,131,131,179,131,131,168, 125,268,0,0,0,0,0,0,0,0,0,0,0,0,0,128, 125,268,268,0,0,0,0,0,0,0,0,600,0,0,0,128, 125,268,268,0,0,0,0,0,0,0,599,0,622,0,0,128, 125,158,0,0,0,158,0,0,0,158,0,597,0,623,0,128, 125,0,0,0,0,285,285,285,285,285,0,0,623,0,158,128, 125,174,174,174,174,174,0,0,0,0,0,0,0,0,0,128, 125,269,269,269,269,172,224,234,234,234,234,234,0,0,0,128, 177,0,0,0,267,172,0,229,10,10,10,0,197,0,0,128, 125,0,0,253,278,172,0,229,0,0,0,0,233,0,0,128, 125,213,211,253,0,172,0,229,238,0,0,0,233,0,0,128, 125,214,216,253,278,172,224,0,0,0,0,0,233,0,0,180, 125,0,0,253,278,0,0,231,231,231,199,231,0,0,0,128, 125,406,0,253,278,0,0,0,0,0,0,0,0,0,0,128, 125,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128, 165,126,126,126,126,126,126,126,126,126,126,126,126,126,126,166 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,307,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,307,0,689,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 my tmx file looks like this but still not work
@KeaSigmaDelta
@KeaSigmaDelta Жыл бұрын
@@youne1982 Oh, so this is a runtime error (occurs when you run your program)? I don't see anything wrong with your tmx file. If you can load it in Tiled, then it's definitely a problem with your code. It's worth double-checking that you're loading the correct tmx file. A simple mistake like that can be confusing. Other than that, I don't know what to suggest. I used the tileson library to load the tile-maps, which use the JSON version instead of *.tmx. If you're loading *.tmx files, then you must use a different library to load it in (or your own code).
She's Perfect
0:46
Greg Doucette
Рет қаралды 15 МЛН
UFC Vegas 93 : Алмабаев VS Джонсон
02:01
Setanta Sports UFC
Рет қаралды 200 М.
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 65 МЛН
Should I have used Unity instead of Raylib for my Indie game?
10:11
Lingon Studios
Рет қаралды 30 М.
Is it that difficult to make a game engine?
7:07
Low Level Game Dev
Рет қаралды 89 М.
Why I Like Programming in C.
3:16
Francisco Jinto Fox
Рет қаралды 24 М.
Drawing SPRITES in Raylib
8:03
Andrew Hamel Codes
Рет қаралды 9 М.
I Made a Neural Network with just Redstone!
17:23
mattbatwings
Рет қаралды 590 М.
CMake, How it Works (At Three Different Levels)
4:36
Kea Sigma Delta
Рет қаралды 8 М.
Ролик про то, почему бессмысленно покупать Китай
14:44
C++ Snake game using raylib - Beginner Tutorial 🐍 (OOP)
1:13:43
Programming With Nick
Рет қаралды 40 М.
Should you learn SDL, SFML, or GLFW? (or GLUT) #indiegamedevontop
2:57
One To Three USB Convert
0:42
Edit Zone 1.8M views
Рет қаралды 440 М.
🔥Идеальный чехол для iPhone! 📱 #apple #iphone
0:36
How charged your battery?
0:14
V.A. show / Магика
Рет қаралды 6 МЛН
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 22 МЛН