Jump to content
  • Advertisement
Sign in to follow this  
Code_Black

Need help with tranlating world cords to player cords

This topic is 530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yes hello. I was hoping to get some help with my game engine. I'm trying to add some collision to my game. The problem is when I try to use the code to detect the collision, BUGS. Please help please help

Share this post


Link to post
Share on other sites
Advertisement

What have you done to debug this?  Where does it crash in the debugger?  What compiler are you using?  What is the error message the compiler returns exactly?

Few here are going to download your code, rename it to a .c/cpp, get the required libraries you use (SFML, etc), set up the build environment, compile and debug it for you.

Share this post


Link to post
Share on other sites
It's not really a bug as maxh as it's not doing what I want.when i try to stop the player from moving when he hit a wall it doesn't work. It stop rhe player from moving in that direction. I know it's somewhere when I try to update player movement.
https://pastebin.com/mihFbL9X

Share this post


Link to post
Share on other sites

How "does it not work" ?

So the end-result is not what you want. The next question is always "why?". To answer, you go down a level.

You should have code that stops the player at the right time (if not, maybe add some code for it :P )[1]. Is that code getting called at all? Is it getting called at the right moment? Does it get the right information at the right time? If these questions are all answered with "yes" then the code itself is broken (it gets called at the right moment, it gets the right information but the end-result it should give isn't there). Ask "why" about that code then.

If the answer to one or more questions is "no", then the code to stop movement is not getting the right information, no wonder it doesn't do the right thing. Next problem is then to ask "why" about the code that is responsible for whatever is not providing the information.

The game is the same every time. Output is not correct, find code responsible for it, check its input. If that is not correct, fix the code that provides that information first. If input is correct, understand why the code is not processing it input correctly, and fix the code.

 

[1] Yep it happens, this week, I wondered if errors in a program got properly forwarded. It turned out I completely forgot one step in the chain! No wonder it never worked :D

Edited by Alberth

Share this post


Link to post
Share on other sites

I don't see anywhere in your code where you test against hitting a block/wall.  That's probably your biggest problem.

I notice it is possible to move both up and down, both left and right, at the same time. Is that something you really wanted?

I believe the formula your previous helper couldn't figure out is this below. It would be easier if SFML kept it in radians with the same zero value as the rest of the math world, but whatever. The dx and dy are the relative distance between the mouse and the resource. The atan2() function returns the angle based on those distances from the origin. The 180/PI is to convert from radians to degrees, and the +180 is because SFML points in a different direction than standard trigonometry.

float dx = mse_pos.x - m_res.x;
float dy = mse_pos.y - m_res.y;
float rotationAngle = ( atan2(dy,dx) * 180/PI ) + 180;

Share this post


Link to post
Share on other sites
No I just one movement at a time. I know it's not checking for walls. That's what I'm trying to do that's why I'm asking for help with translating block corrds to 2d int array corrds. The 2d int array is how I set up the 2d block array. What I need help with is translating the corrds back snd fourth so I can check for collision.

Share this post


Link to post
Share on other sites

The usual approach is for you to give it a try, and when you get stuck, show what you did, tell us what you aim for, and how the current thing is not working exactly.

Learning to program is best done by yourself !

 

I'd start with just translating coordinates only. Get the coordinates of the player, and translate them to world coordinates. Then take those world coordinates, and translate them back to player coordinates (which should of course result in the same coordinates you started with). I guess "player coordinates" means coordinates relative to the player? If so use (0,0,0) at first (ie exactly where the player is).

If that works, make a new player coordinate, say 1 unit in front, and do the same trick again. (Assuming you have 'sides' of your player.)

 

If that also works, that's a first step to collisions.

Share this post


Link to post
Share on other sites
No I just one movement at a time. I know it's not checking for walls. That's what I'm trying to do that's why I'm asking for help with translating block corrds to 2d int array corrds. The 2d int array is how I set up the 2d block array. What I need help with is translating the corrds back snd fourth so I can check for collision.

Share this post


Link to post
Share on other sites

That's what I'm trying to do that's why I'm asking for help with translating block corrds to 2d int array corrds.
Ok.

The other way around may be simpler to start with. Say I have integer coordinate (0, 0), where is that in the world. Similarly, where is (1, 0), and (2, 0), (3,0), (4,0) ...  Can you see a pattern?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!