Platform Movement - Finding slope angle?

For questions about using Classic.

Post » Mon Jan 16, 2012 10:03 pm

I'm starting on working on something, and I need a way to find the angle of a slope. The character would slide down at a set speed depending on the slope.
B
11
S
3
G
8
Posts: 473
Reputation: 4,569

Post » Tue Jan 17, 2012 6:22 am

I'd sample the player's position to calculate the angle. Add two pv to buffer .X and .Y

+ System: Start of layout
-> Sprite: Set 'lastX' to.X
-> Sprite: Set 'lastY' to.Y

+ System: Always (every tick)
-> Text: Set text to "Current slope angle: " & angle(Sprite ('lastX'), Sprite ('lastY'), Sprite.X, Sprite.Y)
-> Sprite: Set 'lastX' to.X
-> Sprite: Set 'lastY' to.Y

Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Jan 17, 2012 8:45 am

I'm assuming "LastX" is a private value?

For the sliding, I just need just need to convert angle to X/Y movement values?Azu2012-01-17 08:53:05
B
11
S
3
G
8
Posts: 473
Reputation: 4,569

Post » Tue Jan 17, 2012 11:27 pm

Yes, 'lastX' and 'lastY' are private variables.

This method will give you the angle from the last tick to the current tick. It is not the angle to the next tick.

However, something like making the speed of the sprite relative to the angle should work. But then you should make that angle relative to the direction of the force.

For example, if you're doing a classic platformer, the downward force will be at 90. Therefor a 30 (down to the right) slope should be treated the same as a 150 (down to the left) slope, speed related.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Jan 19, 2012 12:53 pm

hey tula, could you please make a simple example .cap for this if you have some spare time?

im using a platform behavior but i dont know how to add speed when going downhill and vice versa. it always just overrides the player's speed and input,resulting in player having no control over the slope. ive managed to get the player angle correspond the slope angle using the old fashioned dummy player sprite, but slope speed is kind of puzzling me. first i just ignored it, but now i want to make icy slopes that the player can slide down and try to struggle up with enough speed. i just dont know how to add/subtract to existing speed without completely overriding it.

clodius6662012-01-19 12:54:59
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Thu Jan 19, 2012 9:04 pm

I will see if i can put something toogether. In the meantime, to give you something to try on your own: The platform behavior has 2 actions, "set additional x speed" and "set additional y speed".

Whatever value you use for them, they will add or substract (if they are negative) to the current speed. It is valid per tick, so use an always event for continous additional speed.

the additional speed components can be calculated from an angle using sin and cos:
x_speed = cos(angle) * factor
y_speed = sin(angle) * factor

You just need to differentiate when the character is walking and when sliding. And you need a way to get a dynamic factor (higher factor = faster slide)tulamide2012-01-19 21:10:43
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests