[solved] Help with object following mouse and collision

J

JoltJab

Guest
Hey everyone! I'm a bit new here, hope this is the right spot for this (if not let me know and I'll fix it).

In this 2D side scroller type of game, you have a crystal that's attached to your mouse.

So here's what I'm trying to make: I want the crystal to follow the mouse, but when the mouse moves over a wall, the crystal can't go through it. Also when pulled at an angle, it will pull the crystal across whatever surface it's against (like on an invisible rope or something). Also to make things extra difficult, there are slopes (think megaman X). (It's also going to be limited to a certain radius around a moving main character, but I'll worry about that part after)


--Photoshop mockup example of what I want (pretend the mouse is actually controlling the crystal)--








I've been trying to figure this out myself, I'm having problems with moving the mouse too fast and having the crystal going through some thinner walls. I've tried collision_line from the crystal to the mouse, but a line isn't thick enough to cover the crystal. I've used multiple "collision_line"s in conjunction with place_meeting, but I still can't seem to get it right.

Once it notices it's next position will collide, I think I want to move it in a straight line (aimed at the mouse) one pixel at a time until it collides, but I can't seem to write non buggy code to do that.

I also had another idea where a dynamic instance/collision mask could be created per frame taking up all the space between the crystal's current position to the next position it would be, but I don't know if something like that is possible. I couldn't figure out a way if there is.


As for the sliding against flat and angled surfaces, I haven't even tried that yet. I can't seem to get it to collide right so I haven't been able to try and solve that problem. I would be totally fine if I only got help for the initial collision part though(I would actually be fine with ANY help really).


So would anyone have any suggestions, tutorials, or things to try?
 
F

Facet

Guest
Hi

This is normal and common beginners problem. You have to add on collision move outside object collision in short words, but look over the forum, here a lot of solutions.
 
J

JoltJab

Guest
oh shoot, looks like I did post this in the wrong spot. Thanks to whichever moderator moved it to the correct spot!

Facet: haha yeah I'm a bit of a noob, thanks I'll be sure to look through the forum!

Chim: Thank you! I'll be sure to look over these.

appreciate the responses guys!
 
F

Facet

Guest
oh shoot, looks like I did post this in the wrong spot. Thanks to whichever moderator moved it to the correct spot!

Facet: haha yeah I'm a bit of a noob, thanks I'll be sure to look through the forum!

Chim: Thank you! I'll be sure to look over these.

appreciate the responses guys!
I'm noob too, so problems like this are my daily stuff ;)
 
Top