Scripts / Query about moving objects via LUA

Author
Message
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 17th Nov 2016 16:10
If want to move an object forward 1000 units from point A to point B, and i wanted it to take 5 seconds to do so, what would the correct lua code be?

Is this correct?

ModulateSpeed(e,5000)
MoveForward(e,1000)

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Nov 2016 18:05 Edited at: 17th Nov 2016 18:11
no, if i remember correctly moveforward is fps based command so you would use MoveForward(e,fps/seconds) -> assuming 60fps then you use MoveForward(e,60/5) or MoveForward(e,12)

another way to do it is using SetPosition and the angle of the object.
then you would do (note also assumes 60fps)
dist_per_frame = (distance_to_travel/seconds)/fps
so

you can calculate fps by simply counting a variable every second, i.e.

edit; in this example you would use current_fps as the value to use above
edit2: oh and don't forget you may need to turn physics off to move things correctly
CollisionOff(e)

i don't believe ModualteSpeed adjusts the move command, only AI commands and animation speeds - but it's default is 1 (meaning 100% normal speed, so 5 is 500% faster, 5000 would be way too high)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 17th Nov 2016 19:15 Edited at: 17th Nov 2016 19:16
I didn't understand any of that lol

What I need is a model to rotate towards the player when the player is 1200 away from it, move forward exactly 1000 in exactly 5 seconds, then run an animation. Then I need it to do the exact opposite back to its original position when E is pressed.

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 18th Nov 2016 10:39
The thing i don't understand the most is how can i calculate based on FPS when everyone playing my game will have a different FPS, so no matter what i do, it will take longer or shorter time for everyone who plays, i don't want that to happen, it needs to take a set time to move a set distance.

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 18th Nov 2016 10:50
Would it be any easier to do if i made the entity a character and used AI? If so, how would i do that?


i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Nov 2016 18:54
Take a look at my platform script, it has a function (called scheduler) at the end that gives FPS plus it allows you to make code run at specific intervals, by default it is set to 10ths of a second but you can pass in the interval in milliseconds.

Look in the rest of the script to see how I calculate how far to move the platform each frame based on the FPS.

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: 18th Nov 2016 18:58
Btw, I tried using the AI for movement and found it to be far too buggy, for no apparent reason the AI characters seem to stall or slow down.
Been there, done that, got all the T-Shirts!
PM
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 18th Nov 2016 22:00
Yeah, I was thinking of using your cutscene script, it's going to be great for some of the things I have planned, but for this specific project the problem is I want to have each movement associate with a different animation, ie when it rotates to player to run anim1, when it's moving towards the player to run anim2, and then at the end run anim3, and also at the end have the good old angle squirt promptlocal to press E, which will then repeat the process in reverse, and to be honest there's so much in your script I just wouldn't have a clue where to start adding the anims, the prompt and the key press.


i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Nov 2016 00:06
You've given me an idea here, if I add an animation command plus an extra list the script could do this quite easily. Basically the list would contain the animation frames for animation 1, 2, 3 etc and the command would simply call loop animation when triggered.

Ill have a play around tomorrow to see how well it works.

This might be a cool way to drive simple NPCs.
Been there, done that, got all the T-Shirts!
PM
Tarkus1971
Audio Media Maker
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: England, UK
Posted: 19th Nov 2016 09:43 Edited at: 19th Nov 2016 09:43
What we need are proper kinetic objects, so we can pick up , move , throw objects with "in engine" collision detection. Ideally.
Aftershock Quad Core AMD FM2+ 3.5 GHz 8GB Motherboard and Processor, A7700k apu, Asus GT970 STRIX 4gb Nvidia gfx card.
King Korg Synth, Alesis SR18 Drum Machine, Akai MPX8 sample player, Roland Fantom XA Synth, Axus Digital AXK2 Digital Drum Kit, Novation Ultranova Synth, Waldorf Blofeld Synth.
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 19th Nov 2016 12:43
That's awesome amen, I'm looking forward to seeing this.

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Nov 2016 12:44
I haven't cracked the throwing bit yet but all the rest is possible through scripting. I released an early version of my pickuppable script a while back, I still have to add some functionality to the ezplatform script to allow them to work together, i.e. so that objects can be placed on platforms. (sort of like in Portal where a box can be placed on trigger pads to trigger other stuff to happen)

Actually the ezplatform script needs a new name because it does a lot more than move platforms now, I'm open to suggestions.
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: 19th Nov 2016 16:37
ok how about this version of moving an object based on time the object has already been moving.
i.e. if you want it to take 10s to reach the target and it's already been moving 1s then it should have moved 10% of the total distance (10s/1s)
you do this by converting the elapsed time into a decimal like so
elapsed_time/total_time_to_take
then multiplying the result by the total distance to travel
total_dist * (elapsed_time/total_time_to_take)
then you just need to offset the object from it's original location by the new value.
my code used is here


lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th Nov 2016 17:26
Quote: "What I need is a model to rotate towards the player when the player is 1200 away from it, move forward exactly 1000 in exactly 5 seconds, then run an animation. Then I need it to do the exact opposite back to its original position when E is pressed."

do you mean the exact opposite like this?

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: 19th Nov 2016 18:06 Edited at: 19th Nov 2016 18:07
https://vimeo.com/192264742

I had to turn off the physics on the character to get this to work, don't understand why but with physics on the character floats a few feet off the ground, weird. This probably won't be an issue with custom assets though. (thinking about it this may have something to do with the fact I'm running the lates beta, I'll try it on the last public release)

The fpm expects the scripts to be in a subdirectory called For_Belidos btw, this version of ezplatform.lua is pre-alpha btw so don't overwrite any earlier versions you may have with it!

If you think this is worth pursuing I'll tidy things up a bit and do it 'properly' but for now its something you can play around with.

Two new commands in the movement strings: a<n> starts a single animation l<n> starts a looping animation. a0 stops animation, the animation start and end frames are inserted in a new list, currently only a single list but I'll eventually make it one per entity instance linked by name like the other two lists.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Nov 2016 23:13
Still an issue on the previous release, haven't a clue why it should behave in such a weird way, just another strange GG 'feature to work around.
Been there, done that, got all the T-Shirts!
PM
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 20th Nov 2016 02:21 Edited at: 20th Nov 2016 02:23
Thanks for the help guys, you're both awesome, its much appreciated.

Smallg, that's almost perfect, sorry I should have been clearer, when I said reverse i meant to turn around and return to its original position.

What I was trying to achieve is actually for a character to appear in a doorway, turn to the character, run to them and offer a task, then run back and dissapear once you press E. I know this would be better achieved via AI, but i really wanted to try to do it myself (i always feel cheeky asking for people to script for me), and AI stuff just confuses me, so I thought maybe a set of simple entity moving commands would be easier, but it looks like they're just as hard.

I really do apreciate all your help, I've come a long way learning lua, but there are some things I just can't get, seeing how easy you guys do it makes me feel like I'm in the presence of genius

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
i3 , Intel integrated graphics, 6GB memory, 512GB Generic SATAIII Win8.1.
Intel Celeron (duel Core), Radeon integrated graphics, 4GB memory, 180gB Generic SATAII, WinVista.
Q6600, Intel integrated graphics, 8GB memory, 512GB Generic SATAII, Win7.
Tarkus1971
Audio Media Maker
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: England, UK
Posted: 20th Nov 2016 10:03
Now we just need to be able to move dynamic lights like that.
Aftershock Quad Core AMD FM2+ 3.5 GHz 8GB Motherboard and Processor, A7700k apu, Asus GT970 STRIX 4gb Nvidia gfx card.
King Korg Synth, Alesis SR18 Drum Machine, Akai MPX8 sample player, Roland Fantom XA Synth, Axus Digital AXK2 Digital Drum Kit, Novation Ultranova Synth, Waldorf Blofeld Synth.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 20th Nov 2016 11:07
Lol, I've already bugged Lee about that one, I even asked how something can be described as 'dynamic' when you can't move it!

@Belidos; I've been writing code for 40 years, can't play any musical instruments, can't really speak any language other than English (can just about manage American ), horses for courses as they say.
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-04-30 20:49:51
Your offset time is: 2024-04-30 20:49:51