this jumping crap is starting to make me mad

Blitz3D Forums/Blitz3D Beginners Area/this jumping crap is starting to make me mad

Rubiks14(Posted 2005) [#1]
ok here is my code for when i hit spacebar.....
If KeyHit(57) MoveEntity camera_pivot,0,2,0

...can u please tell me why it makes me move foward instead of up


Rob Farley(Posted 2005) [#2]
Because you're rotated.

Use translateentity if you want to move in a definitive direction regardless of orientation.


Ross C(Posted 2005) [#3]
Or, if your setting up your mesh by rotating it to it's correct orientation, use RotateMesh.


WolRon(Posted 2005) [#4]
Or, if your setting up your mesh by rotating it to it's correct orientation, use RotateMesh.
Or, if your setting up your mesh by rotating it to it's correct orientation, use RotateMesh, NOT ROTATEENTITY.


Rubiks14(Posted 2005) [#5]
but what is wierd is when i use these right here to move foward and sideways it works fine
If KeyDown(17) Or KeyDown(200) MoveEntity camera_pivot,0,0,0.10
If KeyDown(31) Or KeyDown(208) MoveEntity camera_pivot,0,0,-0.10
If KeyDown(30) Or KeyDown(203) MoveEntity camera_pivot,-0.10,0,0
If KeyDown(32) Or KeyDown(205) MoveEntity camera_pivot,0.10,0,0



Rubiks14(Posted 2005) [#6]
and also i don't have any meshes


WolRon(Posted 2005) [#7]
and also i don't have any meshes
Really, then what are you using? Sprites?

Even primitives (cubes, cones, spheres, etc.) are meshes.

---------------------------

You should show more of your code, if you expect any solution


wizzlefish(Posted 2005) [#8]
He's using a camera and a pivot.


sswift(Posted 2005) [#9]
"Because you're rotated."

Now now, no need to be insulting! :-)


RiverRatt(Posted 2005) [#10]
Rubiks14,
The move comand moves an object (mesh,camera,pivot,whatever) by its local coordinets. So watever direction it is facing is its z direction.

Translate moves an object by its global position so it will move the object the direction you give it regardles of the direction it is facing.

So like Rob said use translate rather than move.


Rubiks14(Posted 2005) [#11]
i tried but it didn't do anything


RiverRatt(Posted 2005) [#12]
How did you try it? Lets see the code.


Rubiks14(Posted 2005) [#13]
i've tried many but this is the last 1 i tried, and i don't really care about coming down yet because i know how to get that to work once i get the camera moving in the right way
;graphics 
Graphics3D 800,600
SetBuffer BackBuffer()

;GLOBALS
Global x#,y#,z#,terra_y#

;collision groups
Global SCENERY = 1
Global PLAYER = 2

;light
Global light = CreateLight()
RotateEntity light, 90,0,0

;CAMERA PIVOT
camera_pivot= CreatePivot()
EntityRadius camera_pivot,1.4
EntityType camera_pivot,PLAYER

;CAMERA
Global camera = CreateCamera(camera_pivot)
CameraRange camera,1,1000
CameraFogMode camera,1
CameraFogRange camera,160,200

;SKY
Global sky = CreateSphere(16,camera_pivot)
FlipMesh sky
ScaleEntity sky,100,100,100
PositionEntity sky, 0,50,0
sky_tex = LoadTexture("sky.bmp")
EntityTexture sky,sky_tex

;TERRAIN
Global terrain = LoadTerrain("height2.jpg")
TerrainDetail terrain,2500,True
ScaleEntity terrain, 3,100,3
PositionEntity terrain,-1000,0,-530
ter_tex = LoadTexture("mossyground.bmp")
EntityTexture terrain,ter_tex
EntityRadius terrain,0.2
EntityType terrain,SCENERY

;main loop
While Not KeyHit(1)
; use the mouse to look around
TurnEntity camera_pivot, 0, 0 -MouseXSpeed(), 0
TurnEntity camera_pivot, MouseYSpeed(), 0, 0 
RotateEntity camera_pivot, EntityPitch#(camera_pivot),EntityYaw#(camera_pivot),0
RotateEntity camera_pivot,EntityPitch#(camera_pivot),EntityYaw#(camera_pivot),0
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
; use the w,a,s,d or arrow keys for walking and strafing
If KeyDown(17) Or KeyDown(200) MoveEntity camera_pivot,0,0,0.10
If KeyDown(31) Or KeyDown(208) MoveEntity camera_pivot,0,0,-0.10
If KeyDown(30) Or KeyDown(203) MoveEntity camera_pivot,-0.10,0,0
If KeyDown(32) Or KeyDown(205) MoveEntity camera_pivot,0.10,0,0
If KeyHit(57) TranslateEntity camera_pivot,0,2,0
x#=EntityX(camera_pivot)
y#=EntityY(camera_pivot)
z#=EntityZ(camera_pivot)

UpdateWorld

terra_y#=TerrainY(terrain,x#,y#,z#)+2.0
PositionEntity camera_pivot,x#,terra_y#,z#

RenderWorld
Flip
Wend
End



DJWoodgate(Posted 2005) [#14]
Yaw the pivot, Pitch the camera, ditch the rotations.


Rubiks14(Posted 2005) [#15]
ok, can u do that so i can just put it in my code bc i just tried and i must have done it wrong bc my camera screws up now


Gauge(Posted 2005) [#16]
Well i think I know what your doing:

at the end of the code you are aligning your pivot to the terrain, so do this:

at the begging of your loop I reset the valus of:

align=0
;changed jumpkey to this

If keyhit(57)=true align=2
then at the end
positionentity camera_pivot,x#,terr_y#+align,z#

Here I'll adjust your code:
;graphics 
Graphics3D 800,600
SetBuffer BackBuffer()

;GLOBALS+added align
Global x#,y#,z#,terra_y#,align 

;collision groups
Global SCENERY = 1
Global PLAYER = 2

;light
Global light = CreateLight()
RotateEntity light, 90,0,0

;CAMERA PIVOT
camera_pivot= CreatePivot()
EntityRadius camera_pivot,1.4
EntityType camera_pivot,PLAYER

;CAMERA
Global camera = CreateCamera(camera_pivot)
CameraRange camera,1,1000
CameraFogMode camera,1
CameraFogRange camera,160,200

;SKY
Global sky = CreateSphere(16,camera_pivot)
FlipMesh sky
ScaleEntity sky,100,100,100
PositionEntity sky, 0,50,0
sky_tex = LoadTexture("sky.bmp")
EntityTexture sky,sky_tex

;TERRAIN
Global terrain = LoadTerrain("height2.jpg")
TerrainDetail terrain,2500,True
ScaleEntity terrain, 3,100,3
PositionEntity terrain,-1000,0,-530
ter_tex = LoadTexture("mossyground.bmp")
EntityTexture terrain,ter_tex
EntityRadius terrain,0.2
EntityType terrain,SCENERY

;main loop
While Not KeyHit(1)
align=0 ;added align set to 0 every loop
; use the mouse to look around
TurnEntity camera_pivot, 0, 0 -MouseXSpeed(), 0
TurnEntity camera_pivot, MouseYSpeed(), 0, 0 
RotateEntity camera_pivot, EntityPitch#(camera_pivot),EntityYaw#(camera_pivot),0
RotateEntity camera_pivot,EntityPitch#(camera_pivot),EntityYaw#(camera_pivot),0
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
; use the w,a,s,d or arrow keys for walking and strafing
If KeyDown(17) Or KeyDown(200) MoveEntity camera_pivot,0,0,0.10
If KeyDown(31) Or KeyDown(208) MoveEntity camera_pivot,0,0,-0.10
If KeyDown(30) Or KeyDown(203) MoveEntity camera_pivot,-0.10,0,0
If KeyDown(32) Or KeyDown(205) MoveEntity camera_pivot,0.10,0,0
If KeyHit(57) align=2
x#=EntityX(camera_pivot)
y#=EntityY(camera_pivot)
z#=EntityZ(camera_pivot)

UpdateWorld

terra_y#=TerrainY(terrain,x#,y#,z#)+2.0
PositionEntity camera_pivot,x#,terra_y#+align,z#

RenderWorld
Flip
Wend
End


furthermore I would use:

If keyhit(57)=true or keydown(57)=true align=2

I seem to have trouble reading a keyhit each time, sometimes it reads as key down, and i've even tried enabling directinput. Maybe theres a better way then resetting the value each loop, but i'm not sure.


Sledge(Posted 2005) [#17]

can u do that so i can just put it in my code bc i just tried and i must have done it wrong bc my camera screws up now



Here's a "bare bones" effort that should illustrate most of the stuff you need (with simple placeholder objects and textures).

;system
Graphics3D 640,480,0,1
SetBuffer BackBuffer()
HidePointer

;player
player=CreateCube()

;camera
cam=CreateCamera(player)
CameraRange cam,.1,50
CameraFogMode cam,1
CameraFogRange cam,20,30

;level
level=CreatePlane();SHUTIT!
PositionEntity level,0,-2,0
levelTex=CreateTexture(64,64)
SetBuffer TextureBuffer(levelTex) 
Color 0,255,0 : Rect 0,0,64,64
Color 0,0,255 : Rect 0,0,32,32 : Rect 32,32,32,32
ScaleTexture leveltex,2,2
EntityTexture level,levelTex

;sky
sky=CreateSphere(32,player)
FlipMesh sky
EntityOrder sky,1
skyTex=CreateTexture(512,512)
SetBuffer TextureBuffer(skyTex)
For i=0 To 400
Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
Plot Rnd(0,511),Rnd(0,511) 
Next 
EntityTexture sky,skyTex
SetBuffer BackBuffer()

;collisions
EntityType player,1
EntityType level,2
Collisions 1,2,2,2

;vars
yVel#=0


RotateEntity player,0,0,0
RotateEntity cam,0,0,0,True


While Not KeyDown(1)

;mouselook
my#=MouseYSpeed()*.5
If my#>3 Then my#=3
If my#<-3 Then my#=-3

TurnEntity player,0,-MouseXSpeed()*.3,0
TurnEntity cam,-my#,0,0

If EntityPitch(cam)>0 And EntityPitch(cam)>60 Then RotateEntity cam,60,EntityYaw(cam),EntityRoll(cam)
If EntityPitch(cam)<0 And EntityPitch(cam)<-40 Then RotateEntity cam,-40,EntityYaw(cam),EntityRoll(cam)

MoveMouse 320,240

;jumping
For i=0 To CountCollisions(player)
	If i>0
		If CollisionEntity(player,i)=level
			yVel=0
			If KeyDown(57) Then yVel=.1
		EndIf
	EndIf
Next

;movement
If KeyDown(30) Then MoveEntity player,-.05,0,0 
If KeyDown(32) Then MoveEntity player,.05,0,0
If KeyDown(17) Then MoveEntity player,0,0,.05
If KeyDown(31) Then MoveEntity player,0,0,-.05


;simple gravity
TranslateEntity player,0,yVel,0
yVel=yVel-.004


;sky
RotateEntity sky,EntityPitch(sky),-EntityYaw(player),EntityRoll(sky)


UpdateWorld
RenderWorld
Flip

Wend


Hopefully you should be able to apply the jumping stuff to your code without too much trouble. The mouselook is hardly exemplary but gives you an idea about how to constrain the "head" a bit.


Rubiks14(Posted 2005) [#18]
thanks u guys it finaly works...now i am not so stressed out over it anymore


gpete(Posted 2005) [#19]
That terra_y# stuff comes from an example program that comes with Blitz. A not very understandable one for beginers to use, I know because it messed me up at first also!