Please! Help Me!

Blitz3D Forums/Blitz3D Beginners Area/Please! Help Me!

RiverRatt(Posted 2004) [#1]
I am making a 3d game where the player moves like pacman,
accept with the addition of diagonal movement.
The controls are w,s,a,d,wa,wd,ds,as. All four single buttons work fine and wa and wd works as well.
The problem is that the ds,and as, combos move it at twice the speed as it should and moves it in the wrong direction.
I have tried everything I could think of and am verry fustrated but realy would like to finish a game!
can someone please help me?
I have assembled part of the program with the problem function.




Rob Farley(Posted 2004) [#2]
I have no idea what the hell you're doing there that code is seriously ugly so I'm not going to work through it..

Why aren't you just going something like

Graphics3D 640,480
camera=CreateCamera()
PositionEntity camera,0,0,-50

player = CreateSphere(6)

middle = CreatePivot()
vector = CreatePivot()

; keyboard control (cursor keys)
upkey = 200
downkey = 208
leftkey = 203
rightkey = 205

Repeat
	PositionEntity vector,0,0,0
	
	; shift vector around based on keyboard input
	If KeyDown(upkey) Then TranslateEntity vector,0,1,0
	If KeyDown(downkey) Then TranslateEntity vector,0,-1,0
	If KeyDown(leftkey) Then TranslateEntity vector,-1,0,0
	If KeyDown(rightkey) Then TranslateEntity vector,1,0,0
	
	If EntityDistance(vector,middle)>1
		; keep the speed constant
		PointEntity vector,middle
		MoveEntity vector,0,0,EntityDistance(vector,middle)-1
	EndIf
	
	TranslateEntity player,EntityX(vector),EntityY(vector),EntityZ(vector)
	
	RenderWorld
	
	Flip

Until KeyHit(1)



semar(Posted 2004) [#3]
I strongly suggest you to separate the movement logic by the key press logic.

In other terms, I would do something like this:

.
.
key_status = key_logic()
move_logic(key_status)

;==========================
function key_logic()
;==========================
;check combination of keys and return an unique value
;
if keydown(whatever_A) and keydown(whatever_B) then
return 1
endif
;
if keydown(whatever_C) and keydown(whatever_D) then
return 2
endif
;
if keydown(whatever_E) and keydown(whatever_F) then
return 3
endif
;
;other keys here
;
;==========================
function move_logic(move)
;==========================
;move the player accordingly whith the param passed
select move
case 1
case 2
case 3
;
;other cases here
;
end select

In this way, you should not have any problem regarding double speed and the likes.

More, you seem to move a bunch of entities all together - do you know EntityParent command ? It can help a lot !
:)

Hope this has sense for you,
Sergio.

[EDITED]
Rob, how come you're some millisecs faster than me !!! Do you have some sort of 'still-no-reply-topic search engine' ?
:)


RiverRatt(Posted 2004) [#4]
"I have no idea what the hell you're doing there that code is seriously ugly so I'm not going to work through it.."
Sorry about the sloppy code, the result of changing it 20 or
thirty times.
What it does (not to well) is...
The sphere is the key entity, for colitions and placement
of the dirbox located behind the sphere, and for the pointer box located in front. Then the most important piece
is the robox I made in milkshape.It kinda looks like r2.
The cam stays locked on the sphere. The sphere does not rotate becouse then if I parent the camera to it the cam will turn with it and that is not desired, as the cam should be locked at an angle like Diablo and always face
the same direction (NorthEast). Another reason not to parent the sphere is that when on the roof or outside of
the structure the sphere stays inside the structure this serves to contain the robox from leaving the edge and floating out into space. Now the dirbox "direction box"
controls the turning by relocating it to the right or left front or back, ect... The ROBOX then points its back to the dirbox. And last but not least is the pointer box whitch is there for the light and head to point at. The idea is to have the pointer box attached to the mouse so the head and light rotate 360 for lazer fire.
Anyhow thats the idea of it all.
So all that being the case,Please corrct me if I'm thinking all wrong.
I should parent the dirbox to the to the robox. parent the pointerbox to the to the light and head and leave the cam and sphere the way they are? And I will seperate the key presses and the movement.

PS If you don,t here from me before Dawn i have fell off the edge.
Thanks for the help.


Ethan3850(Posted 2004) [#5]
A word of warning about your key combinations. Some keyboards can't take multple alpha-numberic key presses and I'd change your keys to something like: q, w, e, a, d, z, x, c for directional control.


RiverRatt(Posted 2004) [#6]
I was thinking about making a function for options to switch controls to the arrow keys. I guess I could write
one for for that to be a option. How bad is that? I mean
if a keyboard that can,t handle it, what does it do?
I did not know that thank you.

Anyhow I have it working now. I just did what semar said and it worked perfect. I have spent the day making a ship leval for it. I still nead to change the if statments.
I'm gonna wait until I get the head rotation working cause that'll be part of it.


RiverRatt(Posted 2004) [#7]
"A word of warning about your key combinations. Some keyboards can't take multple alpha-numberic key presses and I'd change your keys to something like: q, w, e, a, d, z, x, c for directional control."

Hey ! Now this is bugging me. Originaly I was only going to have just w,s,a,d individualy but noticed I kept hitting
two keys on accident, so I gave it something to do in that event. Now even if I wen't to the far more confusing " q, w, e, a, d, z,x, c" control whats to keep someone from hitting multiple keys by accident? What keyboards don't support multiple keypresses?


BlitzSupport(Posted 2004) [#8]
Plenty of keyboards don't support certain key combinations, not just a few specific models. Best to offer the option to redefine them, although it's hardly necessary at this stage!


RiverRatt(Posted 2004) [#9]
Ok I have made some of the recomended changes and here is the real code for the game and I would like some constructive coments. It all works alot better with the real leval but this demonstrates the camera and colitions.
It also has Marks tweening code.


Some things I would like to know.
Why do I have to keep the move_box(ent,x#,y#,z#)
call out of the tween or is that for the best.
Do you find the controls comfortable, natural?
Will I get Gorge Lucus send his wookies after me for using an r2-d2 likeness.