I am exploring reactphysics3d.
I have a ship (from Paul
)
local ship = loadObj("3d", "ship.obj")
ship.shape = r3d.BoxShape.new(2, 1, 3)
local v2 = Viewport.new()
v2:setContent(ship)
v2:setPosition(0, 4, 0) -- min 2 for y
v2.body = world:createBody(v2:getMatrix())
v2.body:createFixture(ship.shape, nil, 100)
v2.body:enableGravity(false) |
I have the game loop:
stage:addEventListener(Event.ENTER_FRAME, function(e)
...
local shipx = v2:getX()
local shipy = v2:getY()
local shipz = v2:getZ()
if isright then shipx += 0.10 end
if isleft then shipx -= 0.10 end
if isup then shipy += 0.10 end
if isdown then shipy -= 0.10 end
-- matrix:setPosition(shipx, shipy, shipz)
-- v2.body:setTransform(matrix)
-- v2:setPosition(shipx, shipy, shipz)
-- ship:setPosition(v2:getPosition())
ship:setMatrix(v2.body:getTransform())
end) |
The ship collides with the boxes but how can I move the ship please?
I am almost there (see the commented lines) but at some point the player crashes.
Comments
How can I move the ship in the direction it is facing?
I tried this but getRotationY() is always 0 so that doesn't work.
the project:
I am "rotating" the ship using torque:
@hgy29 I remember the demo/game you did http://forum.giderosmobile.com/discussion/comment/60150/#Comment_60150. Do you mind sharing the code please?
And it won't help you since in my demo, the ball was thrown in a known/fixed direction.
with reactphysics3d, it works pretty much the same as box2d: the collision engine change the transform matrix of the body, then your gideros code copy this matrix to the corresponding sprite. I think your issue is that setting the Matrix of a Sprite doesn't update its rotation/translation nor scale components, it only change its resulting matrix. thus you can't use getRotation() afterwise.
There are ways to compute back rotation angles from the matrix coeficients, but your problem is easier to solve since you don't need the angles, but the direction vector.
For example, if your untransformed ship is pointing toward 'z' axis, then you can get the transformed direction vector with the code below:
Likes: MoKaLux
Likes: keszegh
youtube.com/watch?v=cE1_uHiOArYCode based on gideros 3d collisions demo (hgy29) + ship graphix from Paul.
main.lua = 146 lines of code
But I don't know how to access the setFrictionCoefficient
From the reactphysics doc it's written: And in the gideros github I see this:
I tried these but that don't work:
1- local mat = shipvp.body:getMaterial() mat:setFrictionCoefficient(0.5)
2- shipvp.body:setMaterial(setFrictionCoefficient(0.5))
3- shipvp.body:setFrictionCoefficient(0.5)
Thank you in advance for your help.
shipvp.body:createFixture(objship.shape3, nil, 100) -- shape, transform, mass
What I tried :
1- objship.shape3:setTransform(0, 5, 10)
2- objship.shape3:setPosition(0, 5, 10)
Likes: MoKaLux
to dos:
-
collision filteringDONE, better vehicle controls, better blender texturing!- how to build levels? maybe in tiled?
- make games/apps
PS: the code is dirty
Likes: oleg, plicatibu, SinisterSoft, antix
I tried getting the ship move like a car, no success
I tried getting the ship move like a ship, no success
I tried for days getting the controls right with no success, I would need some help here please!
I am almost ready to do some tutorials to bring some attention to gideros but I would like to get the controls done before
PS: I removed the factory buildings because it was too large for the zip file.
Likes: MoKaLux
I asked the question on reactphysics3d github:
https://github.com/DanielChappuis/reactphysics3d/issues/119
@PaulH could you also please help here ?
I also tried to convert this box2d pdf to reactphysics. My goal would be to kill the lateral velocity.
In b2d, b2dot =
Likes: MoKaLux
Likes: MoKaLux
Now simply using this to control the ship (vehicle)
Now some tutorials!
PS: one little issue with lighting and android. I have this message:
FragmentShader:
0:19: L0003: Keyword 'sampler2DShadow' is reserved
stack traceback:
3dbase/3DLighting.lua:74: in function 'getShader'
3dbase/3DLighting.lua:109: in function 'setSpriteMode'
3dbase/3DShapes.lua:35: in function 'updateMode'
3d_factory/plane.lua:35: in function 'PLANE_3D'
main.lua:33: in main chunk
Likes: hgy29
I am struggling doing some tuts.I have started
My question is: can we get the position of a r3d body on only 1 axis?
I would like to access the position on a certain axis only (for example the body position on the x axis):
Transform doesn't take into account the scale, that would be pretty handy.
Thank you
PS: I see in r3d.cpp file this code:
Likes: MoKaLux
For the scaling I do it this way when I create the obj:<pre class="CodeBlock">
Or you could check if it runs on android first with an if else statement.
Tested on html5 export and that works fine, no lighting errors, so that's only for android (maybe ios too?)
PEACE.