Im doing a runner game with 3 lanes, the lane swap is working and i did it by giving a number for each lane (-1; 0; 1). I want to use this number to detect when to move the camera some units to the side. For some reason what i did isnt working.
I have a var (CameraOffset) that changes value when im in the correct lane, but the camera isnt moving at all, i think its better if you see the blueprint:
I am not sure what the correct answer is, but what I would do is try to change directly the position of the specific camera actor which you are using in your level. So I suggest you change the part in your blueprint that you are using a variable to access the CameraActor(I am talking about the target that is connected to the SetActorLocationAndRotation node) and just drag and drop the camera actor from your level. Then you are going to see a node with the name of your camera actor and below this “from persistent level”. I think it is worth a try, and I hope I helped you.
if you have a player object that already moves from lane to lane, then parent camera to that object, it will move to the lane, when the player moves
if you don’t have an object that already moves from lane to lane, then try checking whether SetLocationAndRotation is being called at all. If Direction variable is not set to Center then it might not be
Longer version
Hey, I’m not that proficient with the blueprints, but let’s see if I understand yours correctly.
You remember which lane you are currently in (Switch on Name, or is it where you wanna go?) and in every frame you set position of the camera based on the player’s position. If this is the case, I might have a bit of a trouble understanding how you swap lanes if you are not in Center lane. What purpose does it serve in first place?
In the second part you change variable CameraOffset that you use to move the CameraActor. I’d probably check whether CameraOffset changes each frame (see what you are plugging into Make Transform node) just to be sure. This should also help you check if the SetLocationAndRotation method is being called at all.
I see a possible problem here, but can’t see if it’s "it’. When does the “Direction” changes (Left, Center, Right)? Is it when player moves from lane to lane, or when camera does? Does it change at all? If it changes when player moves, then it might be that the methods to change camera lane are never called.
If this is true, then there’s a couple of solutions that might be more efficient for you. Thing is, there’s no need to do the lane swapping in Tick function (and it’s a good practice to only keep functionality that can really differ on per-frame basis in Tick for performance reasons). Instead, you can move the camera in the same function where you change CurrentLane variable (or wherever you change Direction variable). This will only get called when necessary (I assume when player pushes a button)
However, if you already have a player object that you can move from lane to lane, try adding the camera to the blueprint of the character. This could save you lot of trouble, as the camera will move every time the player moves (that is in any direction). Check Third Person Character to see how it can be done.
Hopefully this helps you, and hopefully I got what the BP does for the most parts. Cheers