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

  • Home
  • SEARCH
  • 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 6637239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:17:18+00:00 2026-05-25T23:17:18+00:00

Alright, so I need to know how to move a object up/down a 315

  • 0

Alright, so I need to know how to move a object up/down a 315 degree slope based on the code i have for moving said object up/down 45 degree slope. Currently the object moves up/down the 315 degree slope like it’s 45 degrees, which is the wrong way (going up and right when he should be going down and right).

Here is the code:

//you're in a double for loop going through every tile in the map, the int's being used are x, and y

//check if the tile is a slope
if (lv.type[lv.tile[x, y]] == Tiles.SLOPE)
{
    //create a rectangle collision box
    Rectangle tileCol = new Rectangle(x * lv.tileSize, (y * lv.tileSize), lv.tileSize, lv.tileSize + 1);

    //if player collision "col" collides with "tileCol" and you haven't done this before this itteration (only happens once per full double loop)
    if (col.Intersects(tileCol) && !onSlope)
    {   
        //get the angle of the tile
        float angle = lv.angle[lv.tile[x, y]];

        //get the x distance of how far away the player's right is inside the tile
        float dist = (col.X + col.Width) - tileCol.X;


        //constructs the opposite of a right triangle
        float opposite = (float)(Math.Tan(MathHelper.ToRadians(angle)) * (dist));

        if (angle < 90)
        {
            //if player's right is less then or equal to tile's right
            if (col.X + col.Width <= tileCol.X + tileCol.Width)
            {
                //place player on slope. this works properly
                pos.Y = tileCol.Y - opposite;
                //tell the program we don't wanna go through this again until the next full loop starts.
                onSlope = true;
            }
        }

        else if (angle > 90)
        {   
            if (col.X >= tileCol.X)
            {
                //this is where the error is.
                pos.Y = tileCol.Y + lv.tileSize + (dist * -1);
                onSlope = true;
            }
        }
    }
}
  • 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-05-25T23:17:19+00:00Added an answer on May 25, 2026 at 11:17 pm

    I don’t fully understand your code because the way it’s written, your player’s position.Y in the “working” if loop is decremented from the top of the tile, effectively placing him near the top of the rectangle when he’s supposed to be going up from the bottom of the slope. But – based on the code above, the following should work for all angles:

    // Check if the tile is a slope
    if (lv.type[lv.tile[x, y]] == Tiles.SLOPE)
    {
        // Create rectangle collision that is the same size as the tile
        Rectangle tileCol = new Rectangle(x * lv.tileSize, y * lv.tileSize, lv.tileSize, lv.tileSize + 1);
    
        // If player collision "col" standing on "tileCol"
        if (col.Intersects(tileCol) && !onSlope)
        {   
            // Get the angle of the tile
            float angle = lv.angle[lv.tile[x, y]];
    
            // Get the x distance of how far away the player's right is inside the tile
            float dist = col.Right - tileCol.X;
    
            // Figure out how far to offset the player 
            float offset = (float)(Math.Tan(MathHelper.ToRadians(angle)) * (dist));
    
            // If player's right is less then or equal to tile's right
            if (col.Right <= tileCol.Right)
            {
                if (angle % 180 < 90)
                {
                    pos.Y = tileCol.Bottom + offset;
                    onSlope = true;
                }
                else if (angle % 180 > 90)
                {
                    pos.Y = tileCol.Top + offset;
                    onSlope = true;
                }
            }
        }
    

    45 degrees = 1/8 Pi. 315 degrees = 7/8 Pi. The tangent functions give you 1 and -1 respectively depending on the slope, and offset the character accordingly.

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

Sidebar

Related Questions

Alright, currently I have my SWF hitting a php file that will go and
Alright, I know questions like this have probably been asked dozens of times, but
Alright, I'm confused as hell. I have an object that I store in a
Alright, I've been messing around with Nutch and need to know what parameter inside
Alright as a preface I have a need to cache a relatively small subset
Alright, so i need to be able to match strings in ways that give
Alright... my Introduction to Data Structures from CS is so rusty I need to
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright. So I have a very large amount of binary data (let's say, 10GB)
Alright, I know how the fieldset / legend works out in HTML. Say you

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.