Help with your scripting

Adding gravity to a object

Adding gravity to a object

Postby epsilonion » 11 Oct 2016, 10:53

I have been thinging about something that is miles away in my project but not so far away as to not think about it.

In games like cod etc you dont have to think about bullet drop.

bullet trajectory using a raycasting modelling is one way ( raycast from one position to another if the bullet is still under xx distance then raycast again and angle it down), but while this is nice in theory in practice you will be unable to calculate sufficient factors to get to a realistic result. I am thinking that it is best to use a gravity with each bullet that is fired to pull the bullet downwards say setting a weight to each type of bullet (5mm, 7.5mm or larger for sniper).

We have a power amount in the weapon editor so we can calculate velocity and distance but adding x.xx amount of gravity to a bullet would allow the bullet to drop, and emulate bullet drop.

This brings me to another thought leading a moving target with a shot, I guess this would be a raycast and calculating bullet velocity and target distance...

Hmmm the second part was me thinking aloud lol...

Its still food for thought because it would be a great addition to the weapon editor to allow gravity to be set for bullets so people have the choice of setting bullet drop without having to write code (great for artists).. :)

Let me know what you think.
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Adding gravity to a object

Postby epsilonion » 11 Oct 2016, 10:56

I am a dickhead lol

found it http://www.chi-ad.com/Skyline/API/Lua/html/class_physics.html#a0c19f8a98446b7ac67d279061c377aa2

physics.setGravity(x,y,z);

Example given in doc's
Code: Select all
function onInit()
    physics.setGravity(0,-9.8,0);
end


Also found

Use this function to set the mass of an existing rigid body.

Parameters
bodyID : The ID of the rigid body we want to set.
mass : A float value representing the mass of the body.
The mass of a rigid body affects how it will behave in world, use setMass() to change the rigid bodies mass.
The following is a Small Example on how to use this function:

function addRigidBody(mass,friction,bounce)
bodyID = physics.addBody(id,enum.body_Sphere(),0);
physics.setMass(bodyID,mass);
physics.setBounce(bodyID,bounce);
physics.setFriction(bodyID,friction);
end


Another thought was grenades

To have a granade bounce from a wall or a object if it hasnt exploded yet, you would have to set xx seconds and if theres still time left when it collides with a wall etc then bounce so you would have to set the bounce on the granade and the object it collides with.

Use this function to set the bounce amount of an existing rigid body.

Parameters
bodyID : The ID of the rigid body we want to set.
bounce : A float value representing the bounce of the body.
The bounce of a rigid body affects how this object will perform on contact with another rigid body. The higher the value the
greater the rebound bounce will be, setBounce(0) to stop bouncing. Note: the surface this object has contacted must have a
bounce value greater than 0 for any bounce to occure.

The following is a Small Example on how to use this function:

function addRigidBody()
bid = physics.addBody(id,enum.body_Sphere(),0);
physics.setMass(bid,100);
physics.setBounce(bid,0.2);
physics.setFriction(bid,1);
end

You can also setfriction of the grenade to the surface its sliding / bouncing off.

I am thinking that this could also be used on a bullet when it impacts different surfaces such as wood (goes through), brick (goes half way through) and renforced concrete (only goes in an inch or so).

I am learning while openly thinking here.. :D and answering my own questions and thoughts lol .. just jump in if you have thoughts about this as well.. :D
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Adding gravity to a object

Postby SolarPortal » 11 Oct 2016, 13:55

For a bullet, this is a toughie since there are 2 types of bullets: Raycast and Projectiles.

Projectiles would be able to quite easily place a drop when fired.
You can do this either by setting physics.setGravity(); but this will only work for the scene as a whole.
A way of emulating gravity on a single object would be to apply a downwards force of x amount to push the bullet down.
Adjusting scene gravity will affect how all dynamics move around the scene.

Lets face it, physics engines are just applying a a negative Y movement based on velocity every frame, so using a raycast to get distance and a second ray to calculate the elevation drop to get the actual target would not be far from simulated realism.
Using your bullet size would then affect how much is dropped. For a raycast method, this would be the best approach.

Realism is a funny term in graphics since if it looks and acts realistic without using realistic forces and calculations, then its still realistic, just simulated realism lol :P

Cool settings for Grenades, setting bounce to 1 on walls and objects is quite amusing to watch as things bounce around mad lmao :D

I am thinking that this could also be used on a bullet when it impacts different surfaces such as wood (goes through), brick (goes half way through) and reinforced concrete (only goes in an inch or so).
through an object such as wood would be to get the ID Hit, if its wood of a certain thickness based on a array you could store per object, then you could just return the next ray cast in the line to hit instead(i am sure this could be exposed). Then use an advanced feature which totally exists lol :P :P would be to show the damage or destruction lol :P (Note: We don't have this yet... yanking your chain lol :P)

Also, for grenades, use an AI sensor when exploding to get all the objects within a certain range and apply and impulse or force to send them flying. If it is a character or something like an explosive barrel, then call into the damage system to do damage to the object. Would be cool to have ragdolls for explosions haha :P
You can make a character look like they have been sent flying by changing to an animation that is flying backwards and take full control of the vector movement for the character controllers to send them in the direction of the blast wave.

We did something similar by creating a gravity well using an AI sensor where it sucked all the objects in to the center of the sensor sphere. You can create some interesting physics gameplay while messing about lol. :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Adding gravity to a object

Postby epsilonion » 11 Oct 2016, 16:13

Thats something to think about, I am enjoying this discussion.. :d thanks
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 5 guests

cron