Scripts / Move Player forward

Author
Message
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 21st Jun 2019 20:15
Hi. Was asking how would we move the player (outside of the engine)
forward only (would be nice other ways) but this would do fine. I thought
perhaps the move_away.lua script would have some answers. Just not sure
how to convert it to the player. Will experiment, and will be back... cool!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 21st Jun 2019 21:04 Edited at: 21st Jun 2019 21:16
if you want to use physics
Quote: "ForcePlayer ( angle, velocity )"

if you just want to do it like a teleport use the freeze commands
Quote: "SetFreezeAngle(ax,ay,az)
SetFreezePosition(x,y,z)
TransportToFreezePosition()
or
TransportToFreezePositionOnly() --no angle needed, player can look around"

to work out where forwards is you'll need to use amen's
U.Rotate3D( x, y, z, xrot, yrot, zrot )
command
like
local ox,oy,oz = U.Rotate3D( 0, 0, forwarddist, math.rad(g_PlayerAngX),math.rad(g_PlayerAngY),math.rad(g_PlayerAngZ) )
SetFreezePosition(g_PlayerPosX+ox,g_PlayerPosY+oy,g_PlayerPosZ+oz)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 22nd Jun 2019 01:10
Thanks. Exactly right.
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 22nd Jun 2019 04:33
Well, since I tested ForcePlayer with great results, I was happy.
But then realized I was using FreezePosition at the same time,
which overrode ForcePlayer, well... I have to use one or the other!
Would anyone know how difficult it would be to put a MovePlayerForward(v)
function in global.lua?

Also useful would be a FindPlayerForward(v)-- which would return the
x and z coordinates of player < if > moved forward (v) units.

I am trying to use this on a moving platform. So I have to stay up with the
platform, while still allowing for player movement, and the two techniques
conflict with one another. FreezePosition seems an archaic attempt...?

And one more question-- anyone know why this does not move player?;
g_PlayerPosX = g_PlayerPosX + 10 ....... thanks.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 22nd Jun 2019 09:57
Amen already has a script for that, look for ezentitymover or something like that (search doesn't work on mobile so can't link it), that will show you how it's done.

g_PlayerPosX is read only, stops you accidentally moving the player and messing things up, using the correct commands ensures everything else gets updated correctly.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 22nd Jun 2019 15:43 Edited at: 22nd Jun 2019 15:44
GG's main game loop (in very simplified terms) does this:
1) Run the Physics engine (uses Bullet).
2) Update player position.
3) Update Lua globals.
4) Run Lua scripts.
5) Update effects (particles, hud elements, weapons etc).
6) Render scene.
7) goto 1)

Obviously there are a lot of other things going on but my point is that any attempts made in step 4 to update global values will not 'stick', in fact they could cause chaos because any scripts that ran before you make those changes would use the proper values whereas any scripts running after your changes would use the updated values!
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Jun 2019 00:53
Got hit, by a one- two punch! Internet was out for 2 days, and now today
GG is extremely buggy. Getting script errors where the variables are
obviously assigned, but calling nil value error and when I load an old map
to see what happens-- run time errors! -- jiminy! No progress!

But AmenMoses-- please clarify, are you saying that a "MovePlayerForward"
or probably just as good or better a "FindPlayerForward" function could not
be implemented? For the latter, that would be very useful in scripting the
FreezePosition for platform use-- very useful!
While using it that way should not interfere with the ongoings of GG... ?
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th Jun 2019 10:47 Edited at: 27th Jun 2019 10:49
nope, he's explaining why you can't modify the values such as g_PlayerPosX
to find the forward i already showed the code
local forwarddist = 1
local ox,oy,oz = U.Rotate3D( 0, 0, forwarddist, math.rad(g_PlayerAngX),math.rad(g_PlayerAngY),math.rad(g_PlayerAngZ) )
local forwardposx, forwardposy, forwardposz = g_PlayerPosX+ox,g_PlayerPosY+oy,g_PlayerPosZ+oz

now 'forwardposx' ( / y / z ) are the values for "forwards" based on the direction the player is looking

p.s. you will need to require in the utillib.lua in your script too and probably add the other math shortcuts amen uses (just copy and paste from the top of one of the many other scripts amen has done if you're unsure)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 27th Jun 2019 19:20
Btw, they are not math shortcuts (i.e. like you would do in some languages to rename long winded names for readability) they are local references to global functions, like a pointer if you will, which makes execution a lot quicker.

Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 27th Jun 2019 19:51
To move the player simply set the position you want to move to (SetFreezePosition) and call TransportToFreezePosition.

To push the player just use SetGamePlayerControlPushangle and SetGamePlayerControlPushforce.

If you want to fly around the map simply keep track of the position yourself and make sure you call TransportToFreezePosition every frame otherwise physics will take over and the player will fall.

Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th Jun 2019 19:59
Quote: "Btw, they are not math shortcuts"

i meant you take out the word "math" in math.rad etc, not that they are mathematical shortcuts
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Jun 2019 20:03
Thanks again smallg. You have some patience!
I can't decipher it very well, so that makes me nervous to try--
But it's working! I got it to work, so thanks 2 both U.
and AM.

This was a quick test, now to implement it in the main script... :~|'
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Jun 2019 20:05
Luckily, didn't require the shortcuts- after all. pheww...
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Jun 2019 20:35

Do I need to use global variables with the Utility libraries?
It seems to not be allowing me to use locals...?!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Jun 2019 21:18 Edited at: 27th Jun 2019 21:21
All variables in my main script will be allocated to locals,
so please inform me if I cannot use it that way. I got this error

after replacing
"local forwarddist = 1"
to "forwardist[e] = 0" ----- will be varied in script

Example;

10 local forwarddist = {}
11
12 function moveplayerforward_init(e)
13
14 forwarddist[e] = 0

(( in other scripts...))
I've just lately had a lot of issues with GG errors calling variables nil when they
are CERTAINLY already assigned a value of 0 or greater, (like above) along with the table
call; local x = {} right at the beginning... what's going on?

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 27th Jun 2019 21:49
Can't really hep you without seeing the script!

You appear to be calling Rotate3D with an invalid value for the x parameter.


Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Jun 2019 22:00 Edited at: 27th Jun 2019 22:12
Thanks AmenMoses. This was just a throw together test script. It's
not the main one I'm working on, so okay...
What I really need is an understanding of locals and globals and why
and where you can or cannot use them. It's stopped my work several
times (( talking about in the past )) with this "nil" issue when it can't be nil!

Attachments

Login to view attachments
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Jun 2019 22:05 Edited at: 27th Jun 2019 22:21
Edit-- to above (already caught the error in the Rotate3D)
and now
I tried local forwarddist = forwarddist[e] at line 22

So we are moving finally. Throw out the bad script!
Still I wish I could figure out my "nil" issues on the other scripts!
PM

Login to post a reply

Server time is: 2024-03-29 15:15:05
Your offset time is: 2024-03-29 15:15:05