# \[SOLVED\] Instant change of direction with accelerometer + physics?

**URL:** <https://forums.solar2d.com/t/solved-instant-change-of-direction-with-accelerometer-physics/311390>\
**Category:** Uncategorized\
**Created:** [March 12, 2013, 11:29am UTC](https://forums.solar2d.com/t/solved-instant-change-of-direction-with-accelerometer-physics/311390 "2013-03-12T11:29:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nerolyn](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/n/a587f6/32.png) [@Nerolyn](https://forums.solar2d.com/u/Nerolyn)\
**Post date:** [March 12, 2013, 11:29am UTC](https://forums.solar2d.com/t/solved-instant-change-of-direction-with-accelerometer-physics/311390/1 "2013-03-12T11:29:56Z")

</div>

Hi everyone!

I’m working on an accelerometer controlled game where the player controls the gravity to move an object around.

How a left & right controllable environment works:

[lua]  
local function onAccelerate( event )  
if event.yGravity \> 0.1 then  
physics.setGravity(-15, 10)  
else if event.yGravity \< -0.1 then  
physics.setGravity(15, 10)  
else  
physics.setGravity (0, 10)  
end  
end  
end  
[/lua]

Pretty simple, now what happens is that the object decelerates before changing direction, which is logical as we’re talking about physics. But my question is: would it be possible to make the shift of direction instant? I’m thinking some sort of temporary directional velocity added to the object in question, but would need a helping hand here.

Thanks in advance 🙂 [import]uid: 56195 topic\_id: 37607 reply\_id: 67607[/import]

---

<div class="post-metadata">

**Author:** ![BeyondtheTech](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@BeyondtheTech](https://forums.solar2d.com/u/BeyondtheTech)\
**Post date:** [March 12, 2013, 4:15pm UTC](https://forums.solar2d.com/t/solved-instant-change-of-direction-with-accelerometer-physics/311390/2 "2013-03-12T16:15:25Z")

</div>

Have you played with x/y/zInstant instead of x/y/zGravity? They might give you better numbers you need to play with to get the desired result.

[http://docs.coronalabs.com/daily/api/event/accelerometer/index.html](http://docs.coronalabs.com/daily/api/event/accelerometer/index.html)

[import]uid: 6084 topic\_id: 37607 reply\_id: 145802[/import]

---

<div class="post-metadata">

**Author:** ![Nerolyn](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/n/a587f6/32.png) [@Nerolyn](https://forums.solar2d.com/u/Nerolyn)\
**Post date:** [March 12, 2013, 4:51pm UTC](https://forums.solar2d.com/t/solved-instant-change-of-direction-with-accelerometer-physics/311390/3 "2013-03-12T16:51:37Z")

</div>

Wow, what a mistake, I remember giving up on instants but this time they were just what I needed.

Thanks!  
[import]uid: 56195 topic\_id: 37607 reply\_id: 145812[/import]

---

<div class="post-metadata">

**Author:** ![BeyondtheTech](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@BeyondtheTech](https://forums.solar2d.com/u/BeyondtheTech)\
**Post date:** [March 12, 2013, 4:15pm UTC](https://forums.solar2d.com/t/solved-instant-change-of-direction-with-accelerometer-physics/311390/4 "2013-03-12T16:15:25Z")

</div>

Have you played with x/y/zInstant instead of x/y/zGravity? They might give you better numbers you need to play with to get the desired result.

[http://docs.coronalabs.com/daily/api/event/accelerometer/index.html](http://docs.coronalabs.com/daily/api/event/accelerometer/index.html)

[import]uid: 6084 topic\_id: 37607 reply\_id: 145802[/import]

---

<div class="post-metadata">

**Author:** ![Nerolyn](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/n/a587f6/32.png) [@Nerolyn](https://forums.solar2d.com/u/Nerolyn)\
**Post date:** [March 12, 2013, 4:51pm UTC](https://forums.solar2d.com/t/solved-instant-change-of-direction-with-accelerometer-physics/311390/5 "2013-03-12T16:51:37Z")

</div>

Wow, what a mistake, I remember giving up on instants but this time they were just what I needed.

Thanks!  
[import]uid: 56195 topic\_id: 37607 reply\_id: 145812[/import]
