Discuss Scratch

fa_Zos
Scratcher
100+ posts

gravity

I am trying to make gravity and when the cube hits the floor it has to go up one pixel for the whole thing to work but I don't like that and I can't find any other way to do it so can someone please help ma make a gravity engine
Spentine
Scratcher
1000+ posts

gravity

Why don't you just use someone else's platformer engine? You can use this if you want:

define spawn player at position (x) (y) | velocity (xv) (yv)
go to x: (x) y: (y)
set [vx v] to (xv)
set [vy v] to (yv)

define tick | x accel (xa) drag const (dc) jump vel (jv) gravity (g) wall hop xv (wx) wall hop yv (wy)
switch costume to (hitbox v)
set [vx v] to (((vx) + ((<<key (d v) pressed?> or <key (right arrow v) pressed?>> - << key (a v) pressed?> or <key (left arrow v) pressed?>>) * (xa))) * (dc))
change x by (vx)
if <touching (level v)?> then
change y by ([abs v] of (vx))
if <touching (level v)?> then
change y by (()-([abs v] of (vx)))
set [i v] to ((<(vx) > (0)> * (-2)) + (1))
if <<key (space v) pressed?> or <<key (w v) pressed?> or <key (up arrow v) pressed?>>> then
set [vx v] to ((wx) * (i))
set [vy v] to (wy)
else
set [vx v] to (0)
end
repeat until <not <touching (level v)?>>
change x by (i)
end
else
repeat until <touching (level v)?>
change y by (-1)
end
change y by (1)
end
end
change [vy v] by (()-(g))
change y by (vy)
if <touching (level v)?> then
set [i v] to ((<(vy)>(0)>*(-2))+(1))
repeat until <not <touching (level v)?>>
change y by (i)
end
set [vy v] to (<(vy) < (0)> * (<<key (space v) pressed?> or <<key (w v) pressed?> or <key (up arrow v) pressed?>>> * (jv)))
end
switch costume to (character v)
fa_Zos
Scratcher
100+ posts

gravity

nvm i found solution i just used hitbox costume and made it smaller
fa_Zos
Scratcher
100+ posts

gravity

But thanks!

Powered by DjangoBB