Can someone walk me through creating third person camera movement with mouse?

Started by William, May 07, 2023, 17:24:37

Previous topic - Next topic

Midimaster

Do you know that there is a kind of auto-collision?

As far as i can remember:

you use...
Collisions(GroupCharacters,GroupEnvironment,2,0)

but if you use...
Collisions(GroupCharacters,GroupEnvironment,2,2)... the player rises or falls with the terrain
...back from Egypt

William

Quote from: Midimaster on May 18, 2023, 18:02:55Do you know that there is a kind of auto-collision?


okay i set the collision response to 2. can you describe the auto collision? i noticed that at when moving the entity to 0.1 Y axis collision is not triggered, however when the pivot moves above 1.0 Y axis and moves back down to 1.0 or 2.0 collision is triggered. the problem is that the actor is floating above the terrain and not on the ground (0 EntityY(Pivot) and can move below the terrain, collision is not triggered.
im still interested in oldschool app/gamedev

William

So it's working only above the terrain, could this be related to the pivot? i presume this is because terrain and pivot are at the same position that collision isnt triggered.
im still interested in oldschool app/gamedev

William

Quote from: William on May 18, 2023, 20:30:07So it's working only above the terrain, could this be related to the pivot? i presume this is because terrain and pivot are at the same position that collision isnt triggered.
okay, that issue has been resolved. i had to set the entityradius to a lower degree. i have updated the github.

im still interested in oldschool app/gamedev

William

#34
https://github.com/zarosath/blitzKingdoms/blob/master/main.bmx

moveEntity teleports the pivot/player entity instantly 15 degrees in the air.

i am trying to figure out how to make the player move up maybe 8 degrees without seemingly teleporting jnstantly above the ground via moveEntity()
how to make this motion?


  TranslateEntity(Pivot,PlayerVX,PlayerVY,PlayerVZ)
  PlayerOldX = EntityX(pivot,True)
  PlayerOldZ = EntityZ(pivot,True)

  PlayerNewX = EntityX(pivot,True)
  PlayerNewZ = EntityZ(pivot,True)
  PlayerVX = PlayerNewX - PlayerOldX
  PlayerVZ = PlayerNewZ - PlayerOldZ
i am presently trying to understand what this portion of code is for of remiD.

i also was thinking maybe i can use the gravity method to gradually move the player up at a certain motion but im not sure whether i should use positionEntity or the moveEntity Functions.
im still interested in oldschool app/gamedev

William

#35
realized its because KeyDown moves the entity gradually via MoveEntity(0,1,0) but for jumping it requires KeyHit, trying to figure out the best method for gradual motion like KeyDown/1 degree

edit: using KeydDown so far works great the first few jumps then it appears like motion between jumping and falling decreases i have to debug some more/fix gravity code.
im still interested in oldschool app/gamedev

Derron

For jumping you need to use KeyHit ... and for running/turning KeyDown.

There is no reason to play with something different - why? Think of what each Movement "really" does.

When running/turning you will constantly put energy into the action --- like moving your feet forwards.
When jumping (easy mode jumping!) you put energy into "raising into the air" and from then on gravity and initial velocity/movement vector will define everything for you.
Simply said: you cannot "continue jumping into the air" when you are already jumping.

Stuff gets different it you do not jump but are using a jetpack ("thrusting"). Or if you can "hold the key to collect jump energy" (like a "charging" thing ... the player jittering, lightning bolds everywhere... ). Or if you want the "jump key is hold" to fill a kind of "perfect jump body pose" bar (hold too long and it becomes worse again) leading to higher jumps.

But as said: for simple jump it is "KeyHit".


Same to say for weapons (fire vs "power shot-charging", "power punch").


bye
Ron

William

@Derron thanks

i dont know if you saw the project code it is conditional
If KeyDown(key_SPACE) And PlayerIsOnGround = True Then
Print EntityY(Pivot)
MoveEntity Pivot,0,20,0
Print EntityY(Pivot)
EndIf

i understand what your saying about player energy, maybe have an energy variable and jump height according to that variable? maybe some degree of random jump height mixed in too.

i set keydown so the player keeps jumping while key down without having to keep pressing it.
im still interested in oldschool app/gamedev

Midimaster

a MoveEntity 0,20,0 is no real jumpin, but a irreal sudden ghost flight. You can do this, if this belongs to  your story, but it has nothing to do with reallistic body movement

Normaly it would work like this:
Const GRAVITY:Float = ???  ' 0.1?
Const  ENERGY:Float = ???  ' 1.0?
Const  MOTION:Int   = ???  ' 15 ?
Global ySpeed:Float
...
If KeyHit(key_SPACE) And PlayerIsOnGround = True Then
ySpeed=ENERGY
endif
If PlayerTime<Millisecs() And ySpeed<>0
PlayerTime = Millisecs()+ MOTION
ySpeed   = ySpeed - GRAVITY
MoveEntity Pivot, 0,ySpeed,0
If EntityY(Pivot)<0
'  auto floor collision or:
'  PositionEntity Pivot, EntityX(Pivot), 0 , EntityZ(Pivot)
ySpeed=0
EndIf
EndIf

You have to find out which values ENERGY GRAVITY MOTION are the best for your game

...back from Egypt

William

im still interested in oldschool app/gamedev

William

the code you've posted isnt working because there is no force moving the player towards the entity to collide and so playerisonground=false but its necessary to check the player is on the ground before jumping again.
im still interested in oldschool app/gamedev

Midimaster

I thought you have already made an algorithm, that checks the collision between floor a pivot? And the force that moves the player downto the floor is the GRAVITY.

You have to do experiments to find out which ENERGY and GRAVITY is the best for your world. If both constants are tuned very good, you should see a perfect jump.

For resetting your variable PlayerIsOnGround you should find out when the collision happens and here you set PlayerIsOnGround=0
This has nothing todo with the jump itself.
...back from Egypt

William

@Midimaster can you see?

Rem
main client-side application
EndRem
Strict

Framework openb3d.b3dglgraphics

Graphics3D 800,600, 0, 3

Include "player.bmx"
Include "camera.bmx"
Include "createTerrain.bmx"

'variables
Const GroupEnvironment% = 1
Const GroupCharacters% = 2

Const GRAVITY:Float = 0.1
Const  ENERGY:Float = 1.0
Const  MOTION:Int   = 15
Global YAcceleration:Float
Global PlayerTime:Int

' Light the world, todo;maybe put the lighting in bmx zone file. for now it is in main.
Local light:TLight=CreateLight()
RotateEntity light,90,0,0
MoveEntity(pivot,14,0.02,-15) ' lets move the player a little further onto the terrain. Todo: add general player spawn location


' debug entity landmark
Local c:TEntity = CreateCylinder()
ScaleEntity c, 0.2,10,0.2
   PositionEntity c, 12,0.00000000001,-12
' enable collisions
Collisions(GroupCharacters,GroupEnvironment,2,2)

 Repeat

If KeyDown( KEY_RIGHT )=True Then TurnEntity Pivot,0,-1,0
If KeyDown( KEY_LEFT )=True Then TurnEntity Pivot,0,1,0
If KeyDown( KEY_DOWN )=True Then MoveEntity Pivot,0,0,-0.1
If KeyDown( KEY_UP )=True Then MoveEntity Pivot,0,0,0.1
If KeyDown( key_W )=True Then MoveEntity Pivot,0,0.1,0
If KeyDown( key_S )=True Then MoveEntity Pivot,0,-0.1,0

If KeyDown(key_SPACE) And PlayerIsOnGround = True Then
Print EntityY(Pivot)
'MoveEntity Pivot,0,20,0
YAcceleration=ENERGY
Print EntityY(Pivot)
EndIf

If (KeyHit(KEY_R)) 'print coordinates for reference
Print EntityX(Pivot)
Print EntityY(Pivot)
Print EntityZ(Pivot)
EndIf

If  PlayerTime<MilliSecs() And YAcceleration<>0
PlayerTime = MilliSecs()+ MOTION
YAcceleration   = YAcceleration - GRAVITY
MoveEntity Pivot, 0,YAcceleration,0
Print EntityY(Pivot)
If EntityY(Pivot)<0
'  auto floor collision or:
'PositionEntity Pivot, EntityX(Pivot), 0 , EntityZ(Pivot)
YAcceleration=0
EndIf
EndIf

Local WhoCollided:TEntity = EntityCollided(pivot,GroupEnvironment)
If WhoCollided=terrain
     Print "Entity has collided with the terrain"
PlayerIsOnGround = True
Else

PlayerIsOnGround = False
Print "player isnt colliding with anything"
EndIf

If PlayerIsOnGround = False

EndIf
CameraFunction()
UpdateWorld
RenderWorld
Flip 1

'Text 0,0,"Use cursor keys to move about the terrain"

Flip


Until AppTerminate() Or KeyHit(KEY_ESCAPE)



im still interested in oldschool app/gamedev

William

If i comment out
Quoteand Yacceleration<>0
from the if statement then gravity is applied, collision detected and entitycollided playerisonground=true
PlayerTime<MilliSecs() 'And YAcceleration<>0
but what is it checking YAcceleration !not = 0 for?
im still interested in oldschool app/gamedev

Midimaster

Quote from: William on May 21, 2023, 19:38:56but what is it checking YAcceleration !not = 0 for?
yes! you are right! my fault! I did not test it, but wrote it on the fly. It is not necessary in the IF statement
...back from Egypt