A turning object

edited September 2016 in Help request
Not sure why I am having trouble with such a simple concept. I am sure I an missing something simple. I want to turn a car that has speed. No physics.

Graphic = CarGraphic
Position = (300, 200, 0)
Speed = (0, 20, 0)
UseRelativeSpeed = true

Texture = car.png
Pivot = (28, 10, 0)

car = orxObject_CreateFromConfig("CarObject");


	orxFLOAT rotation = orxObject_GetRotation(car);
	rotation += 0.01;
	orxObject_SetRotation(car, rotation);


The car does turn, but the direction is contintuing to go straight down, not in the direction of the rotation.


  • edited September 2016
    The config attribute UseRelativeSpeed only means that the speed will initially be applied relatively. It won't maintain it later on if the orientation of the object changes.

    I updated the phrasing in CreationTemplate.ini to reflect that.

    Regarding your options, I can see two main ones:
    1. Retrieve the relative speed before rotating your object and re-apply it afterward
    2. Manually rotate the speed as well, which will allow you to dissociate the orientation from the speed if that's something desirable with your design. This option is also slightly more efficient, performance-wise.

    Here are some quick code examples:

    orxVECTOR vRelativeSpeed;
    orxFLOAT fRotation;
    orxObject_GetRelativeSpeed(pstCar, &vRelativeSpeed);
    fRotation = orxObject_GetRotation(pstCar);
    fRotation += fAngle;
    orxObject_SetRotation(pstCar, fRotation);
    orxObject_SetRelativeSpeed(pstCar, &vRelativeSpeed);

    orxVECTOR vSpeed;
    orxFLOAT fRotation;
    orxObject_GetSpeed(pstCar, &vSpeed);
    fRotation = orxObject_GetRotation(pstCar);
    fRotation += fAngle;
    orxVector_2DRotate(&vSpeed, &vSpeed, fAngle);
    orxObject_SetRotation(pstCar, fRotation);
    orxObject_SetSpeed(pstCar, &vSpeed);
  • edited September 2016
    Thanks, Iarwain. Makes total sense now.

    I've placed both examples over at:

Sign In or Register to comment.