Scripts / How to apply force on enemy when player collide with enemy

Author
Message
kalyan
5
Years of Service
User Offline
Joined: 4th Aug 2018
Location:
Posted: 5th Aug 2018 12:46
Hi Fellow devs

i want to understand how we can apply physics force when there is a collision event.
How to apply force on enemy when player collide with enemy?

let me know if there is a LUA script for that or a command i missed out.

i found this thread message https://forum.game-guru.com/thread/212442#msg2522330

i have same question. except for bullet or any throwable, there is no other way to add force?
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 5th Aug 2018 16:47 Edited at: 5th Aug 2018 16:48
you can use the ragdoll system to throw characters around using SetEntityRagdollForce(e,limb,x,y,z,v)
x,y,z are the direction of the force and v is the force of the impact
the limb name depends on how the model is set up but you can find the names via g_Entity[e]['limbhit'] and shooting at specific parts of your character
the bad side is that to do this you need to kill the character to make the command have any effect and i don't think it's possible to revive the character afterwards.


the better method would be using the physics engine but i have no idea if it's possible to move characters via physics without causing weird effects, amen would be the man to ask
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: 5th Aug 2018 19:37 Edited at: 5th Aug 2018 19:38
PushObject( objID, vx, vy, vz, rx, ry, rz)

Where objID is the object ID of the object you want to 'push' and vx, vy, vz is the vector and force to apply.

rx, ry, rz are optional parameters and specify the rotational offset, basically it is the offset from the centre of the object at which the force is applied whereas vx,vy,vz specifies the direction in which the force is applied and the force is the 'size' of the vector.

Take a look in the pickuppables.lua script to see how it is used to push objects around.

(also if you want to simply push any physics object the player is looking at you can use the physlib function ObjectPlayerLookingAt( list, force ) which is described in the physlib thread : https://forum.game-guru.com/thread/219758#msg2601608)
Been there, done that, got all the T-Shirts!
PM
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 6th Aug 2018 16:34
Is this added to the entity? or a non static separate entity? I've been trying to add it to my Tank script with no real joy as yet lol (typical) also I'm trying to limit the players vertical view when in the tank as atm you can just look around as you are the player. any pointers or help guys plz
tank script and tank terminal added (add the terminal to my tank model if you have it (in the free section here) https://forum.game-guru.com/thread/219571

adding armour values and testing them today
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 6th Aug 2018 16:58 Edited at: 6th Aug 2018 17:03
You can add it wherever you want, all that matters is that the object ID specified is the one you want to apply the force to and that it is a physics enabled entity.

The effect of the force will depend on the 'mass' of the entity and the size of the force, at present you can only modify the mass directly by changing the physics 'weight' value which is simply a multiplier, i.e. 100 = 1 * whatever the internal mass calculation happens to be, 50 would be 0.5 * and 200 would be double.

I did add a cap to the mass calculation in the engine as really large mass values cause mayhem with the math.


Edited to add:
You may find that the engine overrides any physics applied to NPCs, it may be necessary to turn off the AI for it in order for the physics force to have any effect. (I think that's what the 'Lmbo' thing is all about)
Been there, done that, got all the T-Shirts!
PM
Honkeyboy
3D Media Maker
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 6th Aug 2018 18:18
Right ok m8 so I could say list soldier entities? What im trying to do is have the tank/mech run over npc's so I would have to turn off the physics on impact?
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
kalyan
5
Years of Service
User Offline
Joined: 4th Aug 2018
Location:
Posted: 6th Aug 2018 20:47
Cool, thanks, guys. I didn't think we have these many options let me give a try and get back with results
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 6th Aug 2018 21:19
@HonkeyBoy: For the truck script I ran over Zombies and simply set their health to zero when I collide with them. As soon as they are dead physics takes over and they bounce off the truck quite convincingly.

When combined with smallg's respawn script (or my rewrite of it) you can mow them down all day long.
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-04-20 08:42:16
Your offset time is: 2024-04-20 08:42:16