marionette effect for IOS app - ios

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.

Related

ARKit Tracking - offsetting phone movement

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.

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.

How to move "obstacle" objects. Corona SDK Physics Box2D. Physics Update?

I'm trying to understand the proper way to move "obstacle" objects in corona/box2d. I want to know how to write my code so that the movement is deterministic and in-step with the physics engine. Is this possible?
I'm familiar with Unity which has a physics update (FixedUpdate). Where you can add a bit of code to execute on every physics step. This keeps the physics deterministic, frame and system time independent.
For example, in my game I want to do things like: Make a platform that moves back and forth, make an object that scales up and down in size. I would still like the physics to work properly and allow the ball in my game to bounce off of these for example. Depending on the case, I imagine that I should use either kinematic or dynamic bodies.
I've searched around and the way to periodically manipulate these objects is to use:
timer.performWithDelay. But this has an issue mentioned in the docs "Timers run on system time. If the app is suspended, running timers will not be automatically paused"
Listening to an enterFrame event. But this has a similar issue, if the frame rate drops then the object won't be moved enough. We can use delta time to deal with this, but this has determinism issues (moving an object too much on a lag spike).
transition.to. I'm guessing this is implemented with timer.performWithDelay and has the same issues.
I don't think that any of these will behave deterministic. Any suggestions? Thanks for the help.
You should really use:
object:setLinearVelocity(xVelocity, yVelocity)
or
object:applyForce(xForce, yForce)
instead of transition.to.

How to simulate water in a bottle type of physics using accelerometer using Corona SDK?

I'm developing a gaming application where the user must shake his or her iphone to get objects to move around hitting the borders of the phone. Similar to how water behaves in a bottle.
I know that we can tilt the device to cause a pinball effect, but can we shake the device like shaking a bottle of water?
Thank you in advanced.
With the help of Accelerometer, you can get parameters you need. And in every frame, according to parameters, you can change gravity or apply force to physics objects.
https://docs.coronalabs.com/api/event/accelerometer/index.html
I recommend you to use Instant parameters. You can change gravity according to that.

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