Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411906 Posts in 69428 Topics- by 58476 Members - Latest Member: animtim

June 09, 2024, 06:13:04 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsRotate a box as its pushed over a ledge!
Pages: [1]
Print
Author Topic: Rotate a box as its pushed over a ledge!  (Read 1350 times)
Rat Casket
Level 10
*****


i can do what i want


View Profile WWW
« on: March 06, 2013, 10:53:33 AM »

So basically I want to make this darn cube rotate after its center point passes a ledge, and then fall off. I can push it off ledges just fine as is, but it would just look nicer if it tipped and carried itself off. I don't need any fancy physics or anything aside from making it tilt after its center passes the edge of a platform, tilt 90 degrees towards the direction of the fall, and fall down.

I haven't the slightest clue on how to do this. Any assistance is greatly appreciated.

« Last Edit: March 06, 2013, 11:02:09 AM by Rabbit » Logged

Rat Casket
Level 10
*****


i can do what i want


View Profile WWW
« Reply #1 on: March 06, 2013, 11:01:39 AM »

Meant to post this in technical.
Logged

Ant
Guest
« Reply #2 on: March 06, 2013, 11:01:58 AM »

Well the first thing to keep in mind is that rotating anything close to lofi sprites ingame using image_angle looks rather ugly, so visually you're best off drawing your own rotated sprites.

It's pretty simple to detect if an object is half way off a ledge. First you check to see if the object is actually on the ledge and then you check a collision with an offset, if there's no collision then you know it's close to the edge. So for example this will check if the object is 6 pixels away from falling off to the right:

Code:
if place_meeting(x,y+1,oFloor) and !place_meeting(x+6,y+1,oFloor)

You could use a while a statement to get the exact amount of pixels, but I don't think you'll need to be super precise for what you're after.
Logged
Rat Casket
Level 10
*****


i can do what i want


View Profile WWW
« Reply #3 on: March 06, 2013, 11:02:47 AM »

Much more simple than I was expecting, then. Thanks man!
Logged

Rat Casket
Level 10
*****


i can do what i want


View Profile WWW
« Reply #4 on: March 06, 2013, 08:11:01 PM »

Well let me bug you with this. I've got some basic code in for the block now and it does what I need it to do. Which is fall.

Where about in this code would I need to drop in the rotation?

Code:
x += xSpeed;
y += ySpeed;

ySpeed += gravSpeed;

//vertical collision//
if (place_meeting(x,y+ySpeed,oBlocker)){
    ySpeed = 0;
    onGround = true;
}else{
    onGround = false;
}

//horizontal collision//
if (place_meeting(x+xSpeed,y,oBlocker)){
    while (!place_meeting(x+sign(xSpeed),y,oBlocker)) x += sign(xSpeed);
    xSpeed = 0;
}
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic