How to create a Impulse Vector based on rotation (Cocos2d, Chipmunk, Spacemanager)

So, I'm trying to create a character with two reactive packs - any of which can be launched independently of each other to create a momentum offset from the center of gravity (using Cocos2d, Chipmunk and SpaceManager).

My problem is that, by default, the impulse function does not take into account the current rotation of the object (that is, how it is indicated), so the impulse offset and the direction I use end in the same way no matter what direction the symbol points in.

Im trying to create a more realistic model - where the momentum is based on the existing rotation of the object. I'm sure I can programmatically just maintain a vector variable that contains the current direction that the character is pointing to and use it, but there should be a simpler answer.

Iv heard people write about the worldview and relative coordinates of the body, as well as how impulse is the default world space, and a relative body will correct my problem. It's true? If so, how do you convert between these two coordinate systems?

Any help you could give me would be greatly appreciated.

+3
source share
1 answer

( , ), theta, ix iy,

ix_world = ix * cos(theta) - iy * sin(theta);
iy_world = ix * sin(theta) + iy * cos(theta);

theta cos sin . , PI / 180.0.

, , .

+1

Source: https://habr.com/ru/post/1796333/


All Articles