Anything to do with physics. Rigid Bodies, Kinematic controllers, vehicles etc.

Physic SetPosition usage

Physic SetPosition usage

Postby SpiderMack » 14 Nov 2017, 12:06

Hi,

I have some model with physic component and kinematic setup.
It has a script to move it , but nothing happens ?


function onUpdate(timeDelta)


x,y,z = entity.getPosition(obj);

if( input.keyDown( "z" ) == 1 ) then

x = x + 1 ;

physics.setPosition(obj,x,y,z);

end

end

User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Physic SetPosition usage

Postby SolarPortal » 14 Nov 2017, 16:02

kinematic rigidbodies are designed to be moved not have their position set otherwise collisions and callbacks will never happen.

Try using "physics.move" and "physics.rotate" with kinematics.
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: Physic SetPosition usage

Postby SpiderMack » 14 Nov 2017, 17:59

Physics.move doesn't seem to work on rigidBody kinematic.
User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Physic SetPosition usage

Postby SolarPortal » 14 Nov 2017, 18:05

Thats what the command is designed for..

remember its not a setPosition, its accumulative.. so entering say 0,0,0 will not move it at all.

For example: (pseudo code)
Code: Select all
...
pBodyID = physics.getBodyID(obj);
physics.move(pBodyID, 1, 0, 0) -- will move on the X axis by a unit of 1.
...


try to use timedelta also when moving things to ensure everything moves at the same speed regardless of framerate.
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: Physic SetPosition usage

Postby SpiderMack » 15 Nov 2017, 09:38

It didn't work.

Is there some tutorial somewhere ? The idea is to get some sliding door or to make some flying drone, both with collisions.
User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Physic SetPosition usage

Postby SolarPortal » 15 Nov 2017, 17:20

hmm, it should work, i will have to add it to the list of things to try haha :P
  • Just to check, but on the entity properties, first header have you set it to Dynamic and constant update "on".
  • Have you tried the physics debug visualisation that can be turned on from the scene settings.
  • Try running the move in an update, so every frame it is forced to move..
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: Physic SetPosition usage

Postby StarFire » 15 Nov 2017, 17:33

just tried it and this worked for me.
Added a rigid body action to a box.
Set its "PRB Dynamic" to "kinematic"
Added a micro script with the following code:

Code: Select all

obj = 0;
x = 0;
y = 0;
z = 0;

function onInit(objID)
   obj = objID;
   x,y,z = entity.getPosition(obj)
end

function onUpdate(td)
   pBodyID = physics.getBodyID(obj);
   physics.move(pBodyID, x, y, z)
   x=x+1*td
end



This when run even pushes a ball out of the way.
Note: the move command uses direct/absolute co-ords rather than accumulative. Therefor you have to increment the position on each frame for this to work
Hope this helps :)
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Physic SetPosition usage

Postby SpiderMack » 15 Nov 2017, 23:47

StarFire wrote:just tried it and this worked for me.
Added a rigid body action to a box.
Set its "PRB Dynamic" to "kinematic"
Added a micro script with the following code:

Code: Select all

obj = 0;
x = 0;
y = 0;
z = 0;

function onInit(objID)
   obj = objID;
   x,y,z = entity.getPosition(obj)
end

function onUpdate(td)
   pBodyID = physics.getBodyID(obj);
   physics.move(pBodyID, x, y, z)
   x=x+1*td
end



This when run even pushes a ball out of the way.
Note: the move command uses direct/absolute co-ords rather than accumulative. Therefor you have to increment the position on each frame for this to work
Hope this helps :)



Nothing happens, no movement and i have the right physic setup (constant update, kinematic).
Perhaps something is wrong somewhere in the code, i know Skyline can't show code errors and code validation doesn't works many times.
I'll give it another try later.
User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Physic SetPosition usage

Postby SpiderMack » 16 Nov 2017, 11:48

It works with your code.

However, i noticed if the player goes against the moving object, many times the player passes throught the moving object collision.
Is this normal ?
User avatar
SpiderMack
Skyline Expert
 
Posts: 441
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter


Return to Physics

Who is online

Users browsing this forum: No registered users and 4 guests

cron