3D rotate object

NeoBerlinNeoBerlin Posts: 106Member
edited April 2018 in General Chat

Hi alls,
with the following code, i can move an objekt smoofly by press and release a key...from start position, up and than back to startposition:

var position_in_rest = Vector3()


func _ready():

i do restore the startposition:

position_in_rest.z = translation.z

and in:

func _physics_process(delta):

i have

if pressing_button == true:
    motion = ((position_in_rest.z + 2.5) - self.translation.z) * 0.2

if pressing_button == false:
    motion = ((position_in_rest.z) - self.translation.z) * 0.2

Now i try the same with an other object...
but i only want to rotate it...
and i cant find a way to do it :(
by searching i didnt find what i need.

so do you have an idea?

Thank you


Tags :


  • TwistedTwiglegTwistedTwigleg Posts: 995Admin

    You could try storing the rotation_degress from Spatial.

    You could then try using something like
    var rotation_in_rest = self.rotation_degress
    self.rotation_degress = (rotation_in_rest.x - rotation_degress.x) * 0.2
    if you want to do something similar to the code you posted above.
    (I have not tested the code, so it may not work)

  • newmodelsnewmodels Posts: 120Member

    A more universal way of tranlating an object by speed is to use the delta time.
    deltaValue* speedvalue * TranslationVector
    When using deltaValue in this way, your object will move with at same speed on most all machines. The difference is the slower computers will not be as smooth.

  • NeoBerlinNeoBerlin Posts: 106Member

    thank you for your answers.
    i tried a lot yesterday but didnt found a way.
    with the code from @TwistedTwigleg , my object jumps to hard to the new rotated position...i search for a way to let it soft move on it axis to the new position, otherwise the collision with other objects (here a ball) is too hard...

    @newmodels , sorry...i cant follow you xD

    thank you again

  • newmodelsnewmodels Posts: 120Member
    edited April 2018

    have a look at this code that I got working, it's based on the tutorial godot gives.

    var xmove = 0
    var ymove = 0
    var velocity = Vector2()
    if Input.is_action_pressed("ui_right"):
        velocity.x = 1
        xmove = 1
    if Input.is_action_pressed("ui_left"):
        velocity.x = -1
        xmove = -1
    if Input.is_action_pressed("ui_down"):
        velocity.y = 1
        ymove = 1
    if Input.is_action_pressed("ui_up"):
        velocity.y = -1
        ymove = -1
    #position += velocity.normalized() * movementSpeed
    position.x += xmove * movementSpeed * delta
    position.y += ymove * movementSpeed * delta

    The part that you need to learn is the position.x = position.x + (xmove * movementSpeed * delta)
    You need to follow the same formula on your degree rotation, adjusting the movementSpeed.

    However, take a look at this godot link: http://docs.godotengine.org/en/3.0/tutorials/math/matrices_and_transforms.html
    It explains a more proper way of doing translation with godot. The delta should still be used.

  • newmodelsnewmodels Posts: 120Member

    Ah, reading your comment again, it looks like what you want is slurp!

  • newmodelsnewmodels Posts: 120Member

    other than slurp, something that can simulate a transition to rotation point!
    This will work for a single axis.

    # You might have to switch Origin and Destination with each other Orgin - Destination
    Distance = Destination - Origin
    degreeChange = Distance / speed
    rotation += degreeChange

    You will need to customize and debug.

  • newmodelsnewmodels Posts: 120Member

    I'm sorry for making these fragmented posts. The correct terminology is slerp. You can search slerp on godot manual html pages and find out how to use it. That is the proper way of doing your gradual translation.

  • NeoBerlinNeoBerlin Posts: 106Member
    edited April 2018 Answer ✓

    Hey @newmodels ,
    Thank you very much for all your posts!
    on beginning, you confused me - but by taking a second look on it and studing your codes/ links, i learned a lot about trans and rot objects.

    So at least i found the answer by a lot of try and error and try again - and the answer is so easy, but for finding it, you need the basics - and i found all basics in your posts - so, thank you again!

    Here my way...lol...so easy, haha:

    var rotmotion = 0
    rotmotion = (1.1 - rotation.y) * 0.2

    thats all!...rotation and rotate are the keywords and to know how to diff them xD

    haha, thank you very much

Sign In or Register to comment.