• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] Collision On Trailing Object With 360 Degrees Movement

E

Ends

Guest
Code:
p = obj_player1
t = obj_player1_trail

if keyboard_check(vk_down){ speed = 2;}else{speed = 4;}
if keyboard_check(vk_left){direction += 8}
if keyboard_check(vk_right){direction -= 8}

if(instance_exists(p) == true){
    instance_create(p.x,p.y,t)
}
Hi Community!

Overview: I have a square object (obj_player1) 8x8 that turns left or right at a 360 angle. I would like to destroy obj_player1 when it touches obj_player1_trail.

Problem: When I implement an if statement of instance_place(p.x,p.y,t), it is created on the location of obj_player1. I need to destroy obj_player1 when it touches obj_player1_trail. Unfortunately, obj_player1 gets destroyed instantly.

Goal: I need to find a way to create the instance of obj_player1_trail 8 pixels behind obj_player1 depending where obj_player1 is facing. What is the best/easiest way of implementation?

Thanks in advanced,

Steven
 

Bingdom

Googledom
lengthdir_ functions will be very useful for this.

What you currently are doing, is spawning the object on top of your player, which will collide with it. A way to prevent it is be doing something like this.
Code:
instance_create(x+lengthdir_x(8,direction+180),y+lengthdir_y(8,direction+180), obj_player1_trail);
 

Mick

Member
To get the opposite angle you need for the lengthdir functions you can use this formula: opposite_direction = (direction+180) mod 360
 
E

Ends

Guest
lengthdir_ is exactly what I was looking for, thank you very much!
I modified the lengthdir_ on the instance_create to the length of 4 since it looks nice on execution.
My final code:
Code:
p = obj_player1
t = obj_player1_trail

if keyboard_check(vk_down){speed = 2;}else{speed = 4;}
if keyboard_check(vk_left){direction += 8}
if keyboard_check(vk_right){direction -= 8}

if(instance_exists(p) == true){
    instance_create(p.x+lengthdir_x(4,direction+180),p.y+lengthdir_y(4,direction+180),t)
}

if instance_place(p.x,p.y,obj_outer_walls) or instance_place(p.x+lengthdir_x(8,direction),p.y+lengthdir_y(8,direction),t) {
    instance_destroy();
}
Please mark as solved.
 
Top