Drag And Drop Rotation Shenangins, Help Me Please :(

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?
 

Hulle

Member
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.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
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. ;)
 
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.
Thanks dood!!
 
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.

View attachment 27486

Hope that helps!

PS: Search the manual for the keyword "other" if you aren't sure what it means. ;)
Oh my god thank you so much!! TTwTT
 
Top