Turn Entity Move Mouse?.

Started by Yue, August 28, 2017, 20:47:37

Previous topic - Next topic

Yue



MousePosition.x = GetRawmouseX()
MousePosition.y = GetRawMouseY()

dx = MousePosition.x  - sx
dy = MousePosition.y  - sy


RotationPivot.x = RotationPivot.x  + dx / 10.0
RotationPivot.y = RotationPivot.y  + dy  /10.0





RotateObjectGlobalX(  caja, RotationPivot.y )
        RotateObjectGlobalY( caja, RotationPivot.x )


Sync()


// Salir.
if GetRawKeyReleased( KEY_ESCAPE ) then exit

SetRawMousePosition( sx, sy)



I'm trying to create a third person camera. But this does not work.

The idea is to rotate a screen cube to the left or right, with the mouse moving horizontally and vertically.

Any suggestions?

Steve Elliott

#1
Yue, there is an example I think in the 3D Folder that comes with AGK.  AGK comes with plenty of example projects.

But really, the experts are on the forums:  https://forum.thegamecreators.com/

The experts here are Qube and MikeHart - and Rick Nasher is picking up AGK pretty quickly.

But we are all learning AGK together - which is good  :D  I'm learning the 2d features for my game, so haven't touched 3d yet, sorry.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Yue

Eureka!  :D No problem.


do


MousePosition.x = GetRawMouseX()
MousePosition.y = GetRawMouseY()

print ( MousePosition.x)
dx = MousePosition.x  - sx
dy = MousePosition.y  - sy


RotationPivot.x = 0  + dx / 100.0
RotationPivot.y = 0  + dy /100.0


print ( RotationPivot.y)

SetRawMousePosition( sx, sy)
RotateObjectglobalx(  caja, RotationPivot.y )
RotateObjectGlobaly(  caja, RotationPivot.x )

Sync()


// Salir.
if GetRawKeyReleased( KEY_ESCAPE ) then exit




loop

I am also learning. :)


Now the idea is to look at how to hook the camera to that pivot, I will look at the documentation.



Steve Elliott

#3
Quote
Eureka!  :D No problem.

Haha, glad you worked it out.  Learning is fun!   :D

Quote
Now the idea is to look at how to hook the camera to that pivot, I will look at the documentation.

Yes the documentation and example code seems good with AGK.  Enjoy the learning process  8)
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Yue


I can not seem to hook the camera to the pivot. I'm looking for something related to SetParent or something similar but I do not find anything. My English is bad I use the google translator and this does not help much.

Do you know the command to hook a camera to a pivot?

Steve Elliott

Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Yue

Quote from: Steve Elliott on August 28, 2017, 21:28:00
Your English is bad, my 3D is bad lol.

Does this help?

https://www.appgamekit.com/documentation/Reference/3D/FixObjectToObject.htm


Thanks You!!, No Working here.


I want to hook the camera to the pivot. It says that by default the camera id is 1, but this does not work.




Steve Elliott

#7
Rick Nasher.  Any thoughts?
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Yue

Run here Box Object.


FixObjectToObject( Box1, Box2 )


Error.
// Number 1 Id Camera Main.



FixObjectToObject( 1, Box )



Rick Nasher

#9
Currently the camera is not just a object as in B3D. It's a special one with it's own set of commands.

You could use something like this to look round and then simply update cam position when the player position changes:


Function mouseLook()  // to be upgraded as follow cam,  not finished yet..
grabx#=(halfscreenwidth-getrawmousex())/2.0
graby#=(halfscreenheight-getrawmousey())/2.0

camy#=wrapvalue(camy#-grabx#)
camx#=wrapvaluex(camx#-graby#)
     
SetRawMousePosition(halfscreenwidth, halfscreenheight) // reset mouse back to midscreen.
// limitatitions should go here.

SetCameraRotation(1, camx#,camy#,0 ) // rotate camera & player according to mouse movement
SetCameraPosition(1, GetObjectX(playerID), GetObjectY(playerID)+2, GetObjectZ(playerID)-5)
EndFunction



function wrapvalue(a#)
while a#<0 or a#>360
if a#<0 then a#=a#+360
if a#>360 then a#=a#-360
endwhile
endfunction a#


function wrapvaluex(a#)
//while a#<-90 or a#>90
if a#<-88 then a#=-88
if a#>88 then a#=88
//endwhile
//no actual wrap just limits since agk hangs at 90 deg
endfunction a#

Above is not all my stuff, just added a line or so, but this crudely works and demonstrates the principle.

I'm working on something better. :-) Far from done with it, but getting there, was stuck on couple of other things(GF being part of that). lol

I want an universal player controller that does all:
-switch between 1st and 3rd player.
-mouse/touch/keybd control.
-walk, run, jump, crouch(and perhaps swim :-)
-shoot/use inventory
-etc.

Work in progress..







_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

Rick Nasher

Oh and this might come in handy too:


Function AssignKeys()
   
    #constant KEY_BACK       8
    #constant KEY_TAB       9
   
    #constant KEY_ENTER     13
    #constant KEY_SHIFT     16
    #constant KEY_CONTROL 17
    #constant KEY_ALT 18 // added, wasn't in official list.
    #constant KEY_ESCAPE 27
   
    #constant KEY_SPACE 32
    #constant KEY_PAGEUP 33
    #constant KEY_PAGEDOWN 34
    #constant KEY_END 35
    #constant KEY_HOME 36
    #constant KEY_LEFT 37
    #constant KEY_UP 38
    #constant KEY_RIGHT 39
    #constant KEY_DOWN 40
   
    #constant KEY_INSERT 45
    #constant KEY_DELETE 46

    #constant KEY_0 48
    #constant KEY_1 49
    #constant KEY_2 50
    #constant KEY_3 51
    #constant KEY_4 52
    #constant KEY_5 53
    #constant KEY_6 54
    #constant KEY_7 55
    #constant KEY_8 56
    #constant KEY_9 57
   
    #constant KEY_A 65
    #constant KEY_B 66
    #constant KEY_C 67
    #constant KEY_D 68
    #constant KEY_E 69
    #constant KEY_F 70
    #constant KEY_G 71
    #constant KEY_H 72
    #constant KEY_I 73
    #constant KEY_J 74
    #constant KEY_K 75
    #constant KEY_L 76
    #constant KEY_M 77
    #constant KEY_N 78
    #constant KEY_O 79
    #constant KEY_P 80
    #constant KEY_Q 81
    #constant KEY_R 82
    #constant KEY_S 83
    #constant KEY_T 84
    #constant KEY_U 85
    #constant KEY_V 86
    #constant KEY_W 87
    #constant KEY_X 88
    #constant KEY_Y 89
    #constant KEY_Z 90

    #constant KEY_F1 112
    #constant KEY_F2 113
    #constant KEY_F3 114
    #constant KEY_F4 115
    #constant KEY_F5 116
    #constant KEY_F6 117
    #constant KEY_F7 118
    #constant KEY_F8 119

   
    #constant KEY_SEMICOL 186   
    #constant KEY_EQUALS 187
    #constant KEY_COMMA 188
    #constant KEY_MINUS 189
    #constant KEY_POINT 190
    #constant KEY_SLASH 191
    #constant KEY_SINGLQUOTE 192
   
    #constant KEY_SQRBRLEFT 219
    #constant KEY_BACKSLASH 220
    #constant KEY_SQRBRRIGHT 221
    #constant KEY_HASH 222
    #constant KEY_ACCENT 223 // ' << is called what ? :-)

EndFunction
_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

Yue

Thanks You!! :)



// Bucle Principal.
do
sx = GetDeviceWidth() /2
sy = GetDeviceHeight()/2

MousePosition.x = GetRawMouseX()
MousePosition.y = GetRawMouseY()


dx = MousePosition.x  - sx
dy = MousePosition.y  - sy


RotationPivot.x = 0  + dx / 10.0
RotationPivot.y = 0  + dy /10.0




SetRawMousePosition( sx, sy)
RotateObjectGlobalX(  pivoteJugador, RotationPivot.Y )
RotateObjectGlobalY(  pivoteJugador, RotationPivot.X)


print (GetObjectWorldZ(pivoteCamara))

SetCameraPosition(1,GetObjectWorldX(pivoteCamara),GetObjectWorldY(pivoteCamara), GetObjectWorldZ(pivoteCamara) )

SetCameraLookAt( 1, GetObjectX(pivoteJugador),GetObjectY(pivoteJugador), GetObjectZ(pivoteJugador),0)




Sync()


// Salir.
if GetRawKeyReleased( KEY_ESCAPE ) then exit




loop
end



He managed to hook the camera to a pivot. The idea is that the pivot will be in the middle of the player and the camera will rotate around the player. Orbital camera.

Rick Nasher

_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

Yue

 :o

Mine is very basic. :)


Steve Elliott

Looks good Rick.

But your's is now working Yue.  A good start for a new AGK Member.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb