I am having problems adjusting my position

I am trying to change where on the map my character spawns. I tried changing my mapPos (called Bpos in my code) and fooling around in other parts here and there, but I can’t seem to change my camera’s position.

From a quick glance, it seems to me that what you are missing is initially setting your character’s world position to the desired spawn location.

Sorry if I missed anything. I couldn’t invest much time right now.

1 Like

It may help to note that for this particular project, the maps is effectively the camera. The player is positioned at the centre of the screen and instead of moving the player, we move the map. WorldPos for the player is the relative position between the player and the (0,0) location on the map (that being the top-left corner of the map), whereas ScreenPos is just the position of the player on the screen but is not representative of where the player is in the world.

To summarize all of this: to change the spawn point of the player, change the position of the map itself and not where the player is on the screen.

1 Like

Thank you both for messaging me about this. However, I am starting to think my problem is tied to another problem I am having with VScode. Right now, it’s telling me either raylib.h or raymath.h does not exist, and while it doesn’t stop me from running the code, it runs a previous version (i.e., I changed the window screen size from 800 x 450 to 300 x 300, but it still loads the 845 x 450 version, among others). I posted under the new Q&A section, of this course. If you have any insights on that, please let me know either in this thread or in the Q&A. Again thank you for your comments

I saw that Q&A thread before I came across this one. I’ll do my best to assist you in both.

1 Like

Yes, but as far as I can see, this is achieved by setting the map position to the negative of the player’ world position:

       Bpos = Vector2Scale(Hood.getworldposition(), -1.f);
 
        // Draw the Map
        DrawTextureEx(Background, Bpos, 0.0, 4.0, WHITE);

So I am tempted to double down on my initial statement: the code is missing setting the player’s world position to the custom spawn point.

Putting the player’s screen position in the middle seems alright with the one-time call to setscreenposition.

1 Like

I will add that I found if I comment out the Bpos = Vector2Scale line, changing Bpos does change where my character starts on the map

Right, I’m only pointing out that there’s a design difference between the position of the player on screen (which is what I noticed with the posted code) and what the actual in-world position is. Cause it helps to know that when understanding the problem and its solution.

Which, yes, means that the world position of the player needs to be changed, not the screen position. This also explains the behaviour Molderr gets when commenting out Bpos = Vector2Scale(Hood.getworldposition(), -1.f);. But simply removing that line obscures the solution to the problem, which is to set the world position of the player, which sets the position of the map.

1 Like

So, how would I go about doing that? Unless the answer is discussed later in the lesson plan. Because I assumed moving the Bpos should change where the sprite appears on the map.

While setting world position in this way isn’t mentioned in the course, you should already be familiar with working with worldpos at this point as it’s been used in the Tick function of the character.

What you can do to achieve what you’re looking for is to create a function (let’s call it SetSpawnPosition) then call that function in the place just after you set your character variable. To psuedocode this a bit to demonstrate.

character hood = character{}
hood.SetSpawnPosition(SomeVector)

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms