Scripts / Find front of object? Physics library?

Author
Message
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 3rd Aug 2019 05:29
Was wondering how is the best way to locate the front of an object
regardless of it's angle? For example a vehicle? If that vehicle
turns all over the place, but you would like to monitor the front and also
back / sides of it??

I see physicslibrary has terrain collision function-- but no idea on how to
implement it-- if that's what it's for?

I would suppose that my Q? would be the opposite of smallg's
GetAngleToPoint(e,x,z)
just recently referred to elsewhere. Would be cool to have a
GetPointAtAngle(x,y,z,angle,distance).

Also best way to locate zeropoint of model / entity?
Thanks!

PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 3rd Aug 2019 09:36 Edited at: 3rd Aug 2019 09:42
not sure what you mean by regardless of angle, do you mean if it has rotated or is rotating during game etc?
if you want to the front of an object use its own Y angle (assumes a 0 X & Z) or the Rotate3D command in utillib.lua (for full 3D rotation) to work out the forward direction
modify the calculations to get the sides.
something like

for the sides change the position of 'distance' - i think U.Rotate3D(-distance,0,0... and U.Rotate3D(distance,0,0... should be left / right

so the values fx,fy,fz now hold the world position of the position 'distance' units in front of the model... to check if you hit anything within that distance you can raycast to it
i.e.
if IntersectAll(g_Entity[e]['x'],g_Entity[e]['y'],g_Entity[e]['z'],fx,fy,fz,g_Entity[e]['obj'])...

note; this assumes origin at center of model and that it faces north by default in GG (i.e. the model is set up same as stock media)
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: 3rd Aug 2019 14:47
As smallg's note says, first you have to know what the 'front' of an entity actually means.

Basically when you drop the entity onto the map for the first time you need to note which direction is the 'front', to make things easier I always make sure there is no rotation specified in the fpe file and then rotate the .x model so that the 'front' is +Z direction (i.e. 'into the screen' or 'north'). For physics objects I also move the origin to somewhere sensible, i.e. centre for a ball or wheel, centre of rear axle(s) for a rear wheel drive vehicle etc.

Take a look at the truck script as it contains collision detection based upon the concept of front/rear bumpers and ray casting.

The physics library collision functions are for entities that are completely under Bullet engine control, if you are moving things around explicitly (using PositionObject or similar functions) then they aren't going to be of any use, if you move things around using PushObject then you can use them.

Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 5th Aug 2019 01:43
Thanks Ya'all. Seriously. Just taking a break from this, and been
scripting something new and different. I will try the suggestions,
when I get a chance. Alright!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 5th Aug 2019 18:04 Edited at: 5th Aug 2019 18:05
Sorry for interrupting but this question is for AmenMoses or Smallg
lets say i have an barrel that is lying on the ground and it can either roll forward or backwards depending in witch direction it face, how will one know when it is rolling in the script. ?

Again sorry for intruding in your thread GubbyBlips
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 5th Aug 2019 19:38
Just check it's position every frame, if it is moving then the position will be changing.

But you have just hit on the central problem here, which way is 'forward' and which way is 'backward'?

A barrel doesn't really have a 'front' or 'back'.

You can easily tell if something is moving and in which cardinal direction it is moving (i.e. N, NE or W say ) but whether that is 'forward' or 'backward' is something that is dependent on context within the level. For example you may decide that 'forward' is travelling toward some other point on the map and 'backward' is travelling away from it.

Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 5th Aug 2019 20:49
@AmenMoses, thank you, i was wandering how can i add a rolling sound to a barrel , so i will have to look at its position, and if that change per frame then i can let the script play a rolling sound. ok now i must go look for the lua function to do that. lol , happy hunting for me.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 5th Aug 2019 21:10
g_Entity[ e ].x & g_Entity.z

If either of those is changing over time then the barrel is moving, as the shape is a cylinder you can safely assume the movement is the barrel rolling.

I would check if the barrel is moving for several frames before playing the sound btw, so if you just nudge it a bit the sound doesn't play.
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 5th Aug 2019 22:04
a[e] = g_Entity[ e ].x
b[e] = g_Entity[ e ].z

do some code, or wait...

x[e] = g_Entity[ e ].x
z[e] = g_Entity[ e ].z

if math.abs(a[e] - x[e]) < 10 then
--moved in x coord
do same for z

also can get the "speed"
speed = a[e] - x[e] -- will possibly return negatives...





PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 5th Aug 2019 22:09
cool, thanks a lot will have a go with it.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11

Login to post a reply

Server time is: 2024-05-31 16:29:01
Your offset time is: 2024-05-31 16:29:01