Scripts / Moving Entities with Collision?

Author
Message
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 1st Feb 2018 03:44
Is there no way to control an entity without shutting off collisions?

I have made a bunch of aircraft scripts and while they work great, they have no collision data so the player can just walk through them as well as other entities. Is there away to use commands like MoveForward without completely shutting off collisions?

I thought maybe if i set physics to 0 that would help keep them afloat while the collisions were on but that doesnt seem to work.

Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 1st Feb 2018 08:34
Take a look at any one of the dozens of scripts I have posted that move stuff around to see how it is done.

This link might be appropriate:

https://forum.game-guru.com/thread/219096#msg2592361
Been there, done that, got all the T-Shirts!
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 2nd Feb 2018 03:12
Looking at them now. Some complex stuff going on there

Are you able to get objects to fly with collisions by quickly switching collisions on and off ?
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 2nd Feb 2018 08:48
I'm still learning the innards of the engine but the ResetPosition command moves the physics collision 'box' to match the 'visual' position of the model, if you do this with CollisionOn the two engines start fighting with each other as GG is trying to move the model and Bullet is trying to resist, that's why it judders. ResetRotation is even worse as it will spin madly on the spot!

SetPosition does not move the collision box (I'm calling it a box but in fact it could be a mesh or capsule) which is why you can walk through the object after it has been 'moved'.

How effective the movement by doing the CollisionOff, Re-position, CollisionOn trick is in the physics world depends on the frame rate, especially for fast moving objects.

Basically what happens is that with low frame rate you are moving the object further each time, it isn't really a 'move' as such it is 'transporting' from the old position to the new position so if for example two moving objects are repositioned to the same spot they will visually merge with each other until the next pass of the Bullet engine where it will probably attempt spring them apart again. Unfortunately this causes some really strange behaviour like being able to punch objects through the terrain or having them fly off in weird directions.

The way this is usually dealt with is that all movement should be done via the Bullet engine and if it detects an upcoming collision it generates a call-back to tell the visual side that the movement you asked for cannot be achieved, GG doesn't have a mechanism to do this at present, or at least no mechanism to pass the info back to the script, so getting smooth movement with physics is rather difficult.

In the case of platforms the trick to use is to detect when the player is on the platform and move the player with the platform, the same trick can be used in vehicles but only works well for slow moving ones as if things are moving too fast eventually you will find the player falling through the object or worse getting stuck in it!

Hopefully this will all get fixed now that we have SITD working on it.

As an aside I finally figured out why my original quatlib wasn't working properly, the Bullet engine also uses quaternions to move things around but GG doesn't, the conversion between Euler angles and quaternions was subtly different between my library and the math routines the Bullet engine uses, for the visual side in GG this didn't matter because it will accept 'weird' Euler angles and still show the correct result visually but the repositioning of the collision box is handed off to the Bullet engine and it came up with a different result so the two 'models' ended up in different places!

I'm toying with the idea of replacing my quatlib with direct Lua calls to the same math library that Bullet uses, I would keep the interface to other scripts the same so you would still call the quatlib functions in the same way but under the covers the lib would call the C++ maths routines, the advantage is that I can add SLERP and other cool stuff without having to re-invent the wheel!
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: 2nd Feb 2018 10:20 Edited at: 2nd Feb 2018 10:20
As that last post was a bit boring here is something I'm currently working on:



Still a work in progress but I think it is looking quite good.
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: 5th Feb 2018 08:17
I really need this too, the collision should be on while the player is carrying items as well, so if you are carrying a large box the box would not go through a well it would hit it and if the player persisted the box would be dropped onto the ground. A bit like in Half Life 2. This would open up so many new in game ideas and puzzle style scenarios.

Very nice work in the video AmenRoses. Awesome. I really hope your system will be able to be added "Inside" the engine. Works well.
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, Bluedio Vicotry V Headphones, AKG K141 Studio Headphones, Lenovo Ideapad, with Windows 10 64bit, 8Gb Ram and AMD A10 7th Gen Graphics.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 5th Feb 2018 19:49
There is a newer video here:

https://forum.game-guru.com/thread/219299#msg2595401


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: 10th Feb 2018 15:33
Plus a downloadable standalone demo to play with.

https://forum.game-guru.com/thread/219299#msg2595880
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-22 19:33:10
Your offset time is: 2024-12-22 19:33:10