Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8959351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:24:57+00:00 2026-06-15T15:24:57+00:00

Here is my code that checks the type of tile. If its an inclined

  • 0

Here is my code that checks the type of tile. If its an inclined tile it then updates the
position of the character. As demonstrated in the photo my character does not move along the slope. What am I doing wrong?

bool Entity::PosValidTile(Tile* Tile, int tileX, int tileY)
{
    if(Tile->TypeID == TILE_TYPE_ANGLEUP)
    {
        int Slope, Intercept;
        int newY;

        Vector P1,P2;
        P1.X = tileX; P1.Y = tileY + TILE_SIZE;
        P2.X = tileX + TILE_SIZE; P2.Y = tileY;


        if(X + (Width/2) > tileX)
        {
            Slope = -(P2.Y- P1.Y) / (P2.X - P1.X);

            Intercept = Slope * (-P1.X + P1.Y);

            newY = Slope * ((X + Width/2) + Intercept);

            Y = (newY - Height);

            return true;
        }
    }
}

demonstration

The dimensions of the character are 48 X 96; which are Width and Height respectively. His origin like the tile, is at the upper left corner.

Here is how that function is used

bool Entity::PosValid(int NewX, int NewY)
{

bool Return = true;

int StartX  = (NewX + Col_X) / TILE_SIZE;
int StartY  = (NewY + Col_Y) / TILE_SIZE;

int EndX    = ((NewX + Col_X) + Width - Col_Width - 1)      / TILE_SIZE;
int EndY    = ((NewY + Col_Y) + Height - Col_Height - 1)    / TILE_SIZE;

if(Flags & ENTITY_FLAG_IGNOREMAP)
{
}else
{
    for(int iY = StartY; iY <= EndY;iY++)
    {
        for(int iX = StartX;iX <= EndX;iX++)
        {
            Tile* Tile = Area::AreaControl.GetTile(iX * TILE_SIZE, iY * TILE_SIZE);

            int atileY = iY * TILE_SIZE;
            int atileX = iX * TILE_SIZE;

            if(PosValidTile(Tile,atileX,atileY) == false)
            {
                Return = false;
            }
        }
    }
}

if(Flags & ENTITY_FLAG_MAPONLY)
{
}else
{
    for(int i = 0;i < (int)EntityList.size();i++)
    {
        if(PosValidEntity(EntityList[i], NewX, NewY) == false)
        {
            Return = false;
        }
    }
}

return Return;
}

The function that calls the previous one is my OnMove function.

void Entity::OnMove(float MoveX, float MoveY)
{
if(MoveX == 0 && MoveY == 0) return;

double NewX = 0;
double NewY = 0;

CanJump = false;

MoveX *= Time::TimeControl.GetDeltaTime();
MoveY *= Time::TimeControl.GetDeltaTime();

if(MoveX != 0)
{
    if(MoveX >= 0)  NewX =  Time::TimeControl.GetDeltaTime();
    else            NewX = -Time::TimeControl.GetDeltaTime();
}

if(MoveY != 0)
{
    if(MoveY >= 0)  NewY =  Time::TimeControl.GetDeltaTime();
    else            NewY = -Time::TimeControl.GetDeltaTime();
}

while(true)
{
    if(Flags & ENTITY_FLAG_GHOST)
    {
        PosValid((float)(X + NewX), (float)(Y + NewY));

        X += (float)NewX;
        Y += (float)NewY;
    }else
    {
        if(PosValid((float)(X + NewX), (int)(Y)))
        {
            X += (float)NewX;
        }else
        {
            SpeedX = 0;
        }

        if(PosValid((float)(X), (float)(Y + NewY)))
        {
            Y += (float)NewY;

        }else
        {
            if(MoveY > 0)
            {
                CanJump = true;
            }
            SpeedY = 0;
        }
    }

    MoveX += (float)-NewX;
    MoveY += (float)-NewY;

    if(NewX > 0 && MoveX <= 0) NewX = 0;
    if(NewX < 0 && MoveX >= 0) NewX = 0;

    if(NewY > 0 && MoveY <= 0) NewY = 0;
    if(NewY < 0 && MoveY >= 0) NewY = 0;

    if(MoveX == 0) NewX = 0;
    if(MoveY == 0) NewY = 0;

    if(MoveX == 0 && MoveY  == 0)   break;
    if(NewX  == 0 && NewY   == 0)   break;
}
}

This function is then called in the main Loop Like so
OnMove(SpeedX,SpeedY);
The speeds are calculated as fallows

    SpeedX += AccelX * Time::TimeControl.GetDeltaTime();
    SpeedY += AccelY * Time::TimeControl.GetDeltaTime();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:24:58+00:00Added an answer on June 15, 2026 at 3:24 pm

    I’m giving an “answer” but it probably better fit as a comment… a few points:

    • First question, what’s happening in the debugger? Do you even get in the if?
    • I don’t see a mention of delta time anywhere, it should be used to get smooth time dependent movement (not frame dependent)
    • PosValidTile doesn’t say much about what the function does… you seem to modify your Entity Y value but not the X? if you don’t move horizontally against the slope, it’s normal that you don’t go up either!
    • TILE_TYPE_ANGLEUP doesn’t make much sense to me, as its “angle” is “down” if your character turns and goes from right to left
    • I guess character movement is determined elsewhere? The heading of your character should be taken into account to know on which side of the slope you’re going (your “next” X, which doesn’t seem to be computed here)
    • Is the function here incomplete? not all paths return a value

    Edit: You posted new code where you use PosValidEntity using NewX and NewY – we don’t see where these values are set to, but keep in mind that your PosValidTile seems to modify directly Y, not a “tentative NewY”.

    Also, I’m not too sure what your Intercept is supposed to do. Basically you have your Slope and you want to know how many pixels along the X axis you are, multiply the Slope by this relative value and then add the base Y. In your case Slope is always TILE_SIZE / TILE_SIZE -> 1 so finding your new Y should be as easy as something like – if it’s not always 1, simply multiply the relative X by that slope

    Y = X + (Width/2) - tileX + tileY;
    

    You take the X position of your character, add the Half Width and the remove the base X value of the tile, this gives you how far along the X axis you are on the slope. Since your slope is always 1, you are as far along the Y axis as you are on the X axis, so if you add (or subtract in your case because I think higher values mean lower on the screen in your coordinates?) this value to your base Y you should get your Y value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot get this to work, here is code that I found in another
Here is my Code that I'm trying to run on Mac OS X: import
Here is the code that doesn't work: Enemy.strength = srand((unsigned)time(NULL)) % 10; Enemy.strength is
Here is my code that adds a line to the grid by pressing the
Here is the code that cause me problem since few hours: TabItem newTab =
Here's my code that is not working: print To: ; my $to=<>; chomp $to;
Here is my code that fails: bool Table::win(const Card &card) { for (int i
Here is the code that I have for my cell of my UITableView: forKeys:[NSArray
I have some code here that uses bitsets to store many 1 bit values
I've got some code here that works great on IPv4 machines, but on our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.