1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Drag And Drop Rotation Shenangins, Help Me Please :(

Discussion in 'Programming' started by Benattaous, Nov 11, 2019.

  1. Benattaous

    Benattaous Member

    Joined:
    Nov 11, 2019
    Posts:
    3
    Hey Hey! New programmer here! I'm making a reskinned version of the Space Rocks Tutorial project, and am currently working on a short invulnerability state for the player after respawn. I'm doing this by respawning a "ghost" object of the player that is only capable of moving, before transforming to the full player object after a few seconds, just in case there happened to be an asteroid on the respawn spot - which would cause an immediate game over regardless of life count.

    The problem is; Whenever the "ghost" transforms into the full player object, the momentum and direction of the player is completely reset! It's extremely jarring, and can sometimes lead to an unfair death, so here's my question - How do I get it so that when the "ghost" object is destroyed and replaced by the full player object, the player object maintains the same speed and direction as the "ghost" when it was destroyed?
     
  2. Hulle

    Hulle Member

    Joined:
    Oct 29, 2019
    Posts:
    8
    I don't know about D&D, but I can help you through code:
    Where the item is created, drag in an "execute code" (Like in a alarm trigger or where ever you make the object.

    In the code: (if it is in the ghost, you create the respawned player) Type this:

    Code:
    var make = instance_create_depth(x,y,DEPTH YOU WANT,OBJECT NAME); //Make a new object, give it a local variable name: "make". Replace with var make = instance_create_layer(x,y,LAYER YOU WANT,OBJECT NAME) if you use layers
    make.image_angle = image angle; //Give "make" the image angle of the ghost (Replace with make.direction = direction if you use that)
    make.speed = speed; //Give "make" the speed of the ghost (if you use the built in speed gamemaker uses)
    instance_destroy(); //Destroy the ghost
    
    Hope it helps.
     
    Benattaous and Nocturne like this.
  3. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,984
    What @Hulle says is correct, but in DnD you would do it this way:

    When you create the ship instance, store the ID of the instance in a temporary local variable target (the box at the bottom of the Create Instance node).
    Now, add an "Apply to..." node, and set the "Expression" option to the variable you used to store the ID of the ship instance you just created.
    Now, drag in a "Set Instance Variable" action so it'll be called in the "Apply To", and set the speed to "other.speed" and set the image rotation to "other.image_angle".
    You can destroy the ghost instance at this point now.

    upload_2019-11-11_10-27-58.png

    Hope that helps!

    PS: Search the manual for the keyword "other" if you aren't sure what it means. ;)
     
    Benattaous and Hulle like this.
  4. Benattaous

    Benattaous Member

    Joined:
    Nov 11, 2019
    Posts:
    3
    Thanks dood!!
     
  5. Benattaous

    Benattaous Member

    Joined:
    Nov 11, 2019
    Posts:
    3
    Oh my god thank you so much!! TTwTT
     
    Nocturne likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice