ARKit Tracking - offsetting phone movement - ios

Currently I am trying to record the movements and rotations of my SCNNode. I am recording the movement data to a csv and then examining it afterwards. Everything is working fine except for the fact that when you move the phone, the data changes because of the SCNNode changing in world space. To elaborate, the node isn't moving or rotating but the movement of the phone is messing with the data in a way that makes it looks like it's moving.
I have read Apple's documentation about ARSessionConfiguration.worldAlignment and I think it could be possible to cancel out the movement of the phone using the gravity property of the node (default worldAlignment).
Does anyone have any advice as to how I could achieve this?
Update:
As mentioned above my original approach to solving this was to change the ARSessionConfiguration. When you change that, the only thing that really changes is where the SCNNode starts in the world space. Therefore, the change did not effect how the movement is represented.

Related

how can i move an object while the iphone is being shaken in objective c

I am creating an iphone project where I need to make a ball move in the same direction of the shake while the device is being shaken.. and then take a certain speed and path when the shake event ends.
I have searched the net and have only posts that can detect a shake effect after which you will be able to run a preset animation that you want.. and I have found many tutorials where you can make a ball move depending on the tilt of the screen.. however what I would like to do, is make the ball move depending on all criterias: shake rythm, shake speed, and giroscope tilt.. is that possible?
Thanks
To do this accurately you must use Core Motion framework, specifically CMMotionManager class. Depending on the device capabilities this class provides both accelerometer and gyroscope data.
To get the ball moving in correct way, this would require a function that would translate the received data from CMMotionManager into values you can animate. That is hard to guess, so I suggest creating a basic function that detects the force and direction and then tuning the parameters by testing.

Transferring billiard game state from player to player with box2d

Im using Union server for my iOS (Starling) billiard game.
So far the connections work great.
My question is:
How would you handle the transfer of the ball positions from the opponent.
Lets say I make the break, and I want to copy that shot to the other player?
Do you think its a good idea to send a message over union every frame (x, y)?
Will this cause latency problems?
First about your question:
The game is installed on both devices, the rules are same. So on shot send the white balls force and all other properties you modify. On the receiving device add that force etc. and the ball will repeat the action done by the sending user.
Now the sad part:
I will be the first one to disappoint you - even if you solve your problem and send the message from player to player with out problems the result won't be pleasant: box2d calculations are optimised for performance, but the result will differ as it's calculated with approximate accuracy. As a result even on the same device the balls will end up in a different location on different runs. You won't notice it in one-two hits, but after playing for a minute you'll end up with deferent ball locations.
You can also try to send a message of every ball position in space after all balls stop moving and relocate the remote users ball positions. After that "correcting" message was received return the control to the player.
We had a similar game and I just wrote my own 2d engine. If you're working only with ball to ball and ball to rectangle collisions it's easy to write your own engine.

btRigidBody objects behave strangely when colliding at slow speeds

I'm trying to use Bullet Physics in my iOS game. The engine appears to be correctly compiled in that the demos work fine.
In my game I have the player's ship and some enemy ships. They're defined as btRigidBody objects and btCollisionObjects and I'm using btSphereShapes for collision.
At 'fast' speeds, collisions appear to happen sensibly - things collide and nothing goes 'weird'. If the speeds are very slow though and the player's ship touches a non-moving object the collision happens, but then the player's ship moves at incredible speed over the next few frames and appears a long distance from where it collided - completely out of proportion to the speed it was moving before impact.
To move the things around I'm using setLinearVelocity() each frame, ticking the physics engine, then using getMotionState() to update the rendering code I have.
Part of the issue might be I don't quite understand how to set the correct mass or what the best speeds are to use for anything. I'm mostly sticking numbers in and seeing what happens.
Should I be using Bullet in this way, and are there any guidelines for deciding on the mass of objects? (am I right in assuming that in collisions heavier objects will force lighter objects to move more)
I'm no expert yet in bullet, but I would not use setLinearVelocity. This is just for initial state, once in the world, if you want to give something a push in the right direction, give it an impulse. This is like being hit with an invisible object so is completely compatible with other collisions. Setting the velocity every frame will completely override the physics engines calculations.
I have noticed that when two objects overlap, they repel each other with a force relative to how much they overlap by. I think your setVelocity method is causing objects to overlap, then eventually the physics engine resolves this in an undesirable way.
I am making a space ship game, I make impulses to cancel out the current movement direction, plus impulses to move it in the new direction as long as the ship is not already moving at my chosen max speed.

marionette effect for IOS app

I'm trying to build an app that has a moveable character as its main idea.
The concept:
Every time you shake your Iphone you will shake several parts of the character (arms, legs, torso, head) by its joints.
I managed to use accelerometer to detect the shake effect, but I'm not able to come to a conclusive approach on how to more the character's body parts.
Ideally, every time you shake the phone the character would move around with a gravity effect like.
Any idea about how I could achieve such effect in xcode?
Have you considered using a physics engine?
check out Box2D:
http://box2d.org
If you want a gravity like effect you could attack the limbs to a torso physics body and then apply the force to the "torso" of the character to get a ragdoll type of effect. You could base the force that you apply on how the device was shaken. I'm not sure if that's what your going for or not though for a shake effect.

iOS how to record moves and play them back

I have a game where user controls a character (with his finger) and i would like to add functionality so the user can record his moves while playing and then play it back. The problem is that the game includes physics and i guess it would be very hard to replicate the exact same moves. How can i implement such a system that will perfectly replay all the users actions? Do i have to record every touch and then play back all the touches? Does any one have any experience with this? I am using Box2D for physics.
"We record replays by storing keystrokes and frame numbers" - box2d.org/forum/viewtopic.php?f=3&t=1982&view=next Seems as if it's the only way to do it. Write these to a PLIST or something and you'll have your replays. Also, if your physics isn't already deterministic (ie. random) then just take down the random values too)
From the comments:
"Just record all the position and rotation state for all the objects every frame (or every other possibly), then, when you want to play things back simply skip the physics engine entirely and just reposition your objects every frame from your recorded position/rotation states.
All you'll need to do is make sure your frames for the play-back are the same duration as they were when the physics was running."

Resources