For celing collision have an invisible colission box above the head. if there's any collision with is, make plrgrav#=-1 or anything below zero.
make object cube #,0:set object collision box #,-1,0,-1,1,1,1,1
position object #,plrx#,plry#+10 (this number just has to be above your caaracter),plrz#
if object collision (#,0)>0:plrgrav#=-1:endif
that's what I do anyways, it works pretty well, though I may change it once I start using sparkys.
For jumping, at it's most basic it's just say:
If spacebar()>0 and plrgrav#=0:plrgrav#=4:endif
I'm only giving the most basic stuff, there's a ton more you can add, and I use multiple object for complex movement that uses multiple angles, because I'm using mouse movement. Do this if you want to have the game feel a bit more proffetional:
If spacebar()>0 and plrgrav#=0 and hitkey=0:plrgrav#=4:endif
if spacebar()=0 and plrgrav#=0:hitkey=0:else:hitkey=1:endif
But for really nice jump, you want the leangth you hold it to determine the hight. Here's my gravity code, minus stuff that doesn't pretain to gravity. This also includes a double jump mechanic. This is part of a program still in the early stages, and so is not very organized yet.
if (mouseclick()=1 or mouseclick()=3) and plrgrav#<=0 and plrgrav#>-2 and jumpcheck=0 and clickhold=0
jumpcheck=1
if djump1#>0:plrgrav#=10:djump1#=0:else:plrgrav#=1:jump=4:endif
endif
if jump>0
dec jump
if jump=4 and plrgrav#>0 and (mouseclick()=1 or mouseclick()=3) then plrgrav#=1
if jump=3 and plrgrav#>0 and (mouseclick()=1 or mouseclick()=3) then plrgrav#=2.4
if jump=2 and plrgrav#>0 and (mouseclick()=1 or mouseclick()=3) then plrgrav#=3.8
if jump=1 and plrgrav#>0 and (mouseclick()=1 or mouseclick()=3) then plrgrav#=5.2:thudd=1
if jump=0 and plrgrav#>0 and (mouseclick()=1 or mouseclick()=3) then plrgrav#=6.6:djump1#=6
endif
if plrgrav#<-0.6:thud=1:endif
if plrgrav#=0:jumpcheck=0:endif
`Double Jump Specifics
if djump1#>0 and plrgrav#=0:djump1#=djump1#-tframe#:endif:if plrgrav#<-7:djump1#=0:endif
And here's the clickhold bit so you understand:
if (mouseclick()=0 or mouseclick()=2):clickhold=0
else
if clickholding>0:clickholding=clickholding-1:clickhold=1
else
if mouseclick()=1 or mouseclick()=3 and clickhold=0
clickholding=3
endif
endif
endif
The code you've just shown isn't just your gravity, that's also your movement and collision, which are seperate. I'm generally bad at reading other peoples code. I don't know if it's because mine is really organized,, of if it's just too different. But it seems to me you're cealing code is overkill and that's why it's slowing down. The solution I gave is pretty simple, and extremely fast, unless for some reason you're having trouble with objects on screen. I'm sure that there are people here with better code, but I can garentee the results of this are very nice.
Superman wears Chuck Norris PJ's