Both box2D inclined friction and sprite Orientation

Source: Internet
Author: User
Problem origin: Generally, the fixedRotation attribute of the b2Body of the player is set to true, that is, it cannot be rotated. This ensures that the player will not twist when it is subject to physical force, for example, his character model is always upright. When a player encounters a inclined object, there is only one contact point between it and the inclined surface, so there is no friction

Problem origin: Generally, the fixedRotation attribute of the b2Body of the player is set to true, that is, it cannot be rotated. This ensures that the player will not twist when it is subject to physical force, for example, his character model is always upright. When a player encounters a inclined object, there is only one contact point between it and the inclined surface, so there is no friction

Problem origin:

Generally, the fixedRotation attribute of the b2Body of the player is set to true, that is, the player cannot be rotated. This ensures that the player does not twist when it is subject to physical force, for example, his character model is always upright. When a player encounters an inclined object, there is only one contact point between it and the inclined surface, so there is no friction, which will cause distortion of the player's motion state.

  • If the player's fixedRotation is set to false, it can be rotated. In this case, the friction is normal, but the player's sprite image also rotates, but sometimes it is expected that the sprite remains upright.


Solution: 1. Always fixedRotation = true,

When the player is on the slope, the player body is constructed into a polygon with the oblique edge at the bottom, and the tilt angle is the same as the slope angle. On a plane, the bottom of the body is changed to a plane.

Disadvantages: 1. unable to adapt to the slope of various angles.

2. Because b2Fixture in Box2D cannot be deformed, The b2Body object wants to change its shape. The b2Fixture object must be created and destroyed repeatedly, which is complex and inefficient.


2. When the player is on a plane, fixedRotation = true;

When the player is on the slope, fixedRotation = false; then the sprite image of the player rotates the corresponding angle according to the slope angle.

  • The specific method is probably: Build a slope class inherited from CCSprite, the class members include the b2Body of the slope, the angle of the slope degree, the class method includes the creation method of the slope createInclinePlane (), the degree of the slope is obtained in this method.
  • When degree is required, use getor () of degree to obtain it.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.