Closed MartinAbilev closed 3 months ago
You need to update the physical status within chipmunk
, by calling world.update(ctx.deltaSeconds());
. I recommend reading chipmunk
's official document, its very well written.
OK, I think your real problem is from reusing dynamic_body
, which is only for initialization. In order to get updated position, you should use index returned by world.addObject
to access array world.objects
, which contains cpBody/cpShape
. jok
only get you this far, you need to use c api of chipmunk to get further information, such as position/rotation etc.
thanks for answer. i got world.update(ctx.deltaSeconds()) in my code i just forget type it here.
i looked at chipmunk api. i bet it here kinda z "problem" i got. now
const b = world.objects.items[0].body;
print("b {}\n", .{b});
gives error: cannot format optional without a specifier (i.e. {?} or {any}) @compileError("cannot format optional without a specifier (i.e. {?} or {any})");
sory if im sound bit anoying . but cn ya give smal example how to read this pos from this object list ?? :) plese please im stuck with my project without it!
from api: Chipmunk provides getter/setter functions for a number of properties on rigid bodies. cpVect cpBodyGetPosition(const cpBody body) void cpBodySetPosition(cpBody body, cpVect pos) Position of the body. When changing the position you may also want to call cpSpace.....
i try kinda
const b = world.objects.items[0].body;
const bv = cp.cpBodyGetPosition(b);
print("b {}\n", .{bv});
error: root struct of file 'deps.chipmunk.chipmunk' has no member named 'cpBodyGetPosition' const bv = cp.cpBodyGetPosition(b);
so no much chips api can help me here
Try cp.c.cpBodyGetPosition
.
One more thing, world.objects.items[0].body
is optional type, you might consider using .?
operator to get real pointer.
It seems you are not familiar with basic zig knowledge well enough, I recommend you to read official documentation on ziglang.org more thoroughly. Its required to be able to dig into official document and source code when working with foss project, especially if you choose to use a programming language still being developed like zig.
yuhuu thanks it works now :) yes i just started with zig so sometimes get stuck.
const b = world.objects.items[0].body.?;
const bv = cp.c.cpBodyGetPosition(b);
print("b {}\n", .{bv});
b deps.chipmunk.c.struct_cpVect{ .x = 0e0, .y = 1.0546666e3 } b deps.chipmunk.c.struct_cpVect{ .x = 0e0, .y = 1.0735e3 } b deps.chipmunk.c.struct_cpVect{ .x = 0e0, .y = 1.0925e3 } b deps.chipmunk.c.struct_cpVect{ .x = 0e0, .y = 1.1116666e3 } b deps.chipmunk.c.struct_cpVect{ .x = 0e0, .y = 1.131e3 } b deps.chipmunk.c.struct_cpVect{ .x = 0e0, .y = 1.1505e3 }.....
so i created just one dynamic object globaly
add to world in init
then on update try to read its position, but on every step value is the same :( where on screen object falls down all work as expected...
do i mising something agen ?