存档

2009年11月 的存档

挑战一下真正属于自已的命运。

2009年11月16日 没有评论

       呵呵,项目停掉了,一年来的心血就这样结束了。郁闷。给自已涨薪的意愿也难以再说出口了。

 

       还能说什么呢。命运总是掌握在别人手里。这就是结果。

 

       自已努力了,无悔。

 

       不过我不会甘心的。既然命运总是把我交给无建树的人。那么,我只有自已来抗争了。

 

       告别无知的年代。

 

       我要去挑战一下真正属于自已的命运。

      

分类: 未分类 标签:

Problem using chipmunk

2009年11月10日 没有评论

I made a game that using a character that can moving left or right by touching the screen, above the character, it is a apple, what i need is the apple will fall down, the character may push the apple up again just like playing volleyball.
That’s the problem,what i have learnt from “bounding ball” is give a sprite a shape and body, then they would collide automatically,when i give shape and body to the character, the animation is not work, the character moved and after a second he “jumps” to the starting point,whatever i using setPosition or Action(MoveTo) to sprite are also useless
moving the body is not work too.I use touchmoved to set the body->p,it keeps shaking and when i release the button, it “fly” alway out of bound……….
Can anyone tell me what should i do or give a similar example(e.g. volleyball and something like that),Plx help!!!

I appreciate that if anyone can give me a hand.

Adding a chipmunk body and shape to a sprite is not the best way to go about this. Try not to think from the screen’s point of view! Instead, create a controller that contains a reference to the physics body and the sprite.

Using a physics engine, such as chipmunk, can be a bit daunting. It helps to enable debug drawing. Have a look into how you can best do that! There is some code you can take from the cocos2d chipmunk example, that comes with the normal cocos2d download)

I take it you’ve added a “ground” shape as a static shape and have gravity set?

When you move a body with body->p = cpv(x,y); the problem is that you don’t change the objects state other than it’s position. To the physics engine, it’s like you teleport the object. If the object was falling, it will still be falling.

So now, your falling object is not touching the ground. Its speed increases. You “teleport” it again.. but until it bumps into anything, gravity will keep increasing its falling speed.

So, if you move an object to another point, be sure to reset all forces and the velocity on that object, if this need to be done!

A better way than using body->p is to use these functions:

  • void cpBodySlew(cpBody *body, cpVect pos, cpFloat dt)
  • void cpBodyUpdateVelocity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
  • void cpBodyUpdatePosition(cpBody *body, cpFloat dt)

The documentation of these functions isn’t too ridged, but there’s other documentation out there. Give it a google :-p I haven’t fully mastered using these functions yet either (I’m still trying to get around Chipmunk too) but they’re the way to go about it.

Alternatively you can (instead of setting body->p) set the velocity of the object directly (though cpBodySlew does this for you)

The latest chipmunk code is doing this with a pivot joint in between the object to be grabbed and the mouse (touch): ChipmunkDemo.c.

See also: Mouse interaction

分类: stackoverflow精选, unity3d 标签: