Gyroscopic Sensor Controlling A Gimbal Camera...

OpengiftOpengift Posts: 8Member
edited January 27 in Programming
extends Spatial

var x = 0.0
var y = 0.0

func _process(delta):
    var reading = Input.get_gyroscope()
    x = (reading.x)
    y = (reading.y)

    var y_rotation = 0
    if y > 0.000000:
        y_rotation += 0.0005
    if y < 0.000000:
        y_rotation -= 0.0005
    self.rotate_object_local(Vector3.UP, y_rotation)

    var x_rotation = 0
    if x > 0.000000:
        x_rotation += 0.0005
    if x < 0.000000:
        x_rotation -= 0.0005
    $InnerGimbal.rotate_object_local(Vector3.RIGHT, x_rotation)


    $InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -0.2, 0.2)
    self.rotation.y = clamp(self.rotation.y, -0.2, 0.2)

Comments

  • OpengiftOpengift Posts: 8Member

    i dont have a gyroscope phone to test it on

  • cyberealitycybereality Posts: 1,454Moderator

    Unfortunately, you can't get good readings from just a gyroscope. You need to take all the readings from accelerometer gyroscope and (optionally) a magnetometer. This is generally called sensor fusion, and you can find the sensors demo for an example of how to do this.

    https://github.com/godotengine/godot-demo-projects/tree/3.0-d69cc10/misc/sensors
    (or find it in the template section of the godot project screen)

    If you want to code it yourself look into the madgwick filter, which was the best method I found.
    https://x-io.co.uk/open-source-imu-and-ahrs-algorithms/

    Note, this is really complex and there is about zero chance of you getting it working without a physical device you can test on. Once you see the code, you'll see it's much more complex.

  • OpengiftOpengift Posts: 8Member

    i brought a new phone, and got the template demo working... is there anyway i can make it sense tilts up down, and across so the scene is kind of 2.5d ?

  • OpengiftOpengift Posts: 8Member

    anyways thanks for your answer, ive got another demo kind of working i just need to convert float to vector3.x and it shoud work the sensor controlls the alien in this demo

  • OpengiftOpengift Posts: 8Member
    edited February 3

    func _physics_process(delta):

    apply_impulse(Vector2() , (Vector2(Input.get_accelerometer().x*10, 0 )))
    ed = get_position().x
    
    $Gimbal.rotate_object_local(ed,Vector3(),Vector3())
    
  • OpengiftOpengift Posts: 8Member

    what do i need to do here to make ed a Vector3

  • TwistedTwiglegTwistedTwigleg Posts: 4,292Admin

    You may be able to construct a Vector3 using the y value of the accelerometer. Something like this (completely untested):

    var sensor_vector = Vector3(Input.get_accelerometer().x*10, 0, Input.get_accelerometer().y*10)
    

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file