0
votes

I am looking for some info on how I can get my sprite to change its rotation by changing the angle of the sprite.

Basically here is how it is set up. Imagine a rocket that is sitting in a stationary position. The physics body is the shape of the rocket, with the tip pointing to the top. Now I apply an immediate impulse to the rocket to send it into the air. While in the air, I would like to use the accelerometer to rotate the sprite. With the rotation, I am expecting the direction of the sprite to change. Unfortunately, The sprite goes straight up and down instead of the direction it is rotated, even though the texture and physics body is rotated. I am having a hard time trying to find info on what techniques are used to achieve the results I want. Most examples have a continuous force, but I only have the initial force with no change after that. I have played around with linearDamping and angularDamping, but that was no help. I have also tried attaching another physics body to the tip to make the tip more heavy to see if the direction will change, but that didn't help either. My only work around that worked is to change the gravity direction, But I would like to avoid this. Any help or direction would be appreciated.

1
If I understand, you're using the accelerometer to rotate the sprite, which is working, but there's no sideways impulse on the spite to give it sideways movement. You'd also like the amount of sideways movement to correspond with the rotation of the Sprite, so it looks natural. Why don't you use the accelerometer to apply a force to the Sprite (the force is applied whilst the device is tilted) and then rotate the Sprite manually to match its new velocity vector?Steve Ives
A force or impulse to a physics body is, by default, applied to the centre of mass, causing no rotation, but they can also be applied to a specified point in the body, which might cause the rotation and sideways movement in one go. You could apply the force/impulse at the base to simulate the gimballing of the engines.Steve Ives
You can calculate the magnitude of the current velocity and then update the velocity based on the accelerometer's x and y multiply by the magnitude.Epsilon
@SteveIves I do not want to apply any more force than what is givenKnight0fDragon
@Epsilon, we have thought of that, it is an option, but we are wondering if there was something that involves actual physics that could achieve this. We just do not understand why when the rocket is not at a 45 degree angle, the rocket does not change direction, wouldn't the air resistance cause the direction to change?Knight0fDragon

1 Answers

0
votes

I think the solution you may be looking for is in Sprite Kits SKFieldNode class.

https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKFieldNode_Ref/#//apple_ref/occ/clm/SKFieldNode/linearGravityFieldWithVector:

The linearGravityFieldWithVector: is probably your best bet. It applies a linear gravity field in a direction you set.

You can also check out electricField which is similar however you can change the charge to positive or negative.