Problem with gravity?

Blitz3D Forums/Blitz3D Programming/Problem with gravity?

Guy Fawkes(Posted 2012) [#1]
Hi all. I'm having a bit of a problem in my game with yes, u guessed it.... Gravity... -.- For some reason when my player would try to run up a hill, the gravity keeps him from doing that, and pushes him back down the hill only when holding down the movement key. I have simulated this glitch with a simple plane, player, and collision sphere demonstration. Can someone PLEASE help me get it to where I can use any rate of gravity, and the player will still have a different gravity when he collides with the ground, so he STOPS sliding down hills? ><


Here's the code:





Thanks to all that help! :)


RGR(Posted 2012) [#2]
.

Last edited 2012


Guy Fawkes(Posted 2012) [#3]
ignoring that smart alec comment, can anyone else help please? :)


Rob the Great(Posted 2012) [#4]
This one's an easy one. Change the collision response of type_player,type_land from 2 to 3. Problem solved.

Check out the response 3 in the user manual. http://blitzbasic.com/b3ddocs/command.php?name=Collisions&ref=3d_cat

Quoted from you:

Can someone PLEASE help me...so he STOPS sliding down hills?



Quoted from the manual:

Collisions src_type,dest_type,method,response
...
response - what the source entity does when a collision occurs.
1: stop
2: slide1 - full sliding collision
3: slide2 - prevent entities from sliding down slopes




Kryzon(Posted 2012) [#5]
ignoring that smart alec comment, can anyone else help please? :)

He could've used kinder language, but you shouldn't ignore his suggestion just because of this. Did you use the forum search? if not, you're the one missing out.

As he's said [and I agree], there are several threads on gravity. Nobody here wants\will be able to reproduce for you all the discussions that took place in previous threads, especially with your reputation.


Guy Fawkes(Posted 2012) [#6]
Ignoring that last rude comment, I already DID use the search... Now I'm having another problem. Compile this code to see what is going on... There is a problem when the player lands back on the ground. It needs to be CONSISTENT gravity, so my player can ALWAYS run up or down a mountain. I have replaced the mountain with a simple smooth sphere for now. The yvel must ALWAYS equal 0.0 when on the ground, and the gravity must ALWAYS pull the player down, to stop the player from "bouncing all the way down the mountain", when running down the mountain.


Here's the code:





Any help is greatly appreciated! :)


Thank You! :)


ando(Posted 2012) [#7]
Hi Thundros, I tried to look at your code so maybe I could help but is too tricky for me so I post a different version and maybe help, maybe not.
Good luck to you. :)



Const width=800,height=600,depth=16

Graphics3D width, height, depth

SetBuffer BackBuffer ()


; --------------------------------------------
;    light
; --------------------------------------------

AmbientLight 140,140,140

lite=CreateLight(2)
PositionEntity lite, 0,3000,0
LightRange  lite,5000

; ---------------------------------------------
;    Terrain
; ---------------------------------------------

terrain=CreatePlane()
PositionEntity terrain, 0, -10, 0
EntityColor terrain,0,64,0

hill=CreateSphere(64)
ScaleEntity hill,25,25,25
PositionEntity hill,0,-15,50
EntityColor hill,0,0,64

; ---------------------------------------------
;    Man1
; ---------------------------------------------

man1 = CreateCube ()
EntityRadius man1, 2


camera=CreateCamera()
CameraRange camera, 1, 5500
PositionEntity camera, 0, 5, -20

many#=EntityY(man1)

;-----------------------------------------------
;    Collisions
;-----------------------------------------------

EntityType terrain, 1
EntityType hill, 1
EntityType man1, 2

Collisions 2, 1, 2, 3

;-----------------------------------------------

HidePointer

frameTimer=CreateTimer(60)

;-----------------------------------------------
;-----------------------------------------------
;                    MAIN LOOP
;-----------------------------------------------
;-----------------------------------------------

Repeat

WaitTimer(frameTimer)

;---------------------------------------------------------------------------------
;    Man1
;---------------------------------------------------------------------------------

mxs = MouseXSpeed()
mys = MouseYSpeed()
xpos=-mxs
ypos=mys

yv#=EntityY(man1)-many

many=EntityY(man1)
	
checkcoll=EntityCollided ( man1,1 )

If checkcoll>0 And jumpcheck=1 Then jumpcheck=0

If checkcoll=0 And yv>0 And jumpcheck=0
   yv=0
EndIf

If KeyDown(57)=1 And checkcoll>0
   yv=.6
   jumpcheck=1
EndIf

MoveEntity man1,0,yv-.03,0

TurnEntity man1, 0, xpos, 0

If MouseDown (2) Or KeyDown (200)=1
   MoveEntity man1,0,0,.2
EndIf

If KeyDown (208)=1
   MoveEntity man1,0,0,-.2
EndIf

PointEntity camera,man1


;-------------------------------------------------------------------------------


	MoveMouse width/2,height/2

	UpdateWorld

	RenderWorld

	Flip

    Delay 10

Until KeyDown (1)

End


Last edited 2012


RGR(Posted 2012) [#8]
.

Last edited 2012


Midimaster(Posted 2012) [#9]
it may be, that the hills are too steep to walk it?

Your player moves only forward. So if he goes uphill he always will collide with the ground. Because of this the collision makes him slip down.

I would suggest to check, if his new position after moving is above or below the terrain (there are special commands in B3D for this). And now you could adjust his y-position.


Guy Fawkes(Posted 2012) [#10]
RGR, go hijack ur own thread u jerk. -.- Im done being the jerk here. its YOUR turn. -.- @Ando, thank you! :) @Midimaster, thank you! :)


Guy Fawkes(Posted 2012) [#11]
@Ando, for some reason, the player jumps up a bit when u stop moving on the hill.


ando(Posted 2012) [#12]
Yes there seems to be some momentum.

You could increase .03 to increase gravity
MoveEntity man1,0,yv-.03,0


Or decrease the .2 to slow the player down

If MouseDown (2) Or KeyDown (200)=1
MoveEntity man1,0,0,.2
EndIf

If KeyDown (208)=1
MoveEntity man1,0,0,-.2
EndIf


Amon(Posted 2012) [#13]
@Thundros

Why don't you figure it out yourself? You have a serious case of anti-social personality disorder. Get it checked out.

I've had enough of reading these boards and seeing your rude, stupid behaviour. Get a grip and learn to code. Your questions could be answered in minutes with a forum search and a little brain activity.

Expecting people to bow to your stupid coding whims then calling them rude when they offer advice you don't like, specifically if it is advice to learn to code or search, is not on.

You will never be a coder. You're too lazy and don't have what it takes. Why don't you go colour some books with crayons? Try to stay within the lines though.

Last edited 2012


Guy Fawkes(Posted 2012) [#14]
Thanks Ando! :) Amon, u do the same thing as RGR. Ur the 1 with the personality disorder. How bout u go get checked out. Im done with MY attitude. How bout u? :) Have a nice day :) P.S. I do not let ur petty insults phase me anymore. :) Have a good day! :)

Last edited 2012


Guy Fawkes(Posted 2012) [#15]
Hmmm.. Ando, the more I increase the gravity, or increase the speed, the more the player can't climb the hill it seems


ando(Posted 2012) [#16]
If you don't want jump then take out this-
If KeyHit(57) yv=.6

and put this in the same place-
If EntityCollided(man1,1)=0 and yv>0 then yv=0

:)
Don't forget to put those other numbers back to original. The gravity and speed.

Last edited 2012


Guy Fawkes(Posted 2012) [#17]
I do want jump, Ando :) It's just that extra momentum I don't want :) Thanks, Ando :)


ando(Posted 2012) [#18]
Well...you could try taking out that last EntityCollided line and put in this little mess. :)

checkcoll=EntityCollided ( man1,1 )

If checkcoll>0 And jumpcheck=1 Then jumpcheck=0

If checkcoll=0 And yv>0 And jumpcheck=0
   yv=0
EndIf

If KeyDown(57)=1 And checkcoll>0
   yv=.6
   jumpcheck=1
EndIf


I also stuck it in the full code further up there.

Last edited 2012


Guy Fawkes(Posted 2012) [#19]
Thanks, Ando! :) It works a beauty! :)


I did add some text to show the yv variable, and put it in windowed mode, and turned off pointentity camera,man1, so u can see the actual effects of yv :)


Here's the code:





Thanks, Ando! :)


ando(Posted 2012) [#20]
Good one :)