Looking for Custom Alternative to 8 Direction Movement

Show 40 post(s) from this thread on one page
Page 2 of 3 First 1 2 3 Last
• 2nd September 2015, 09:49 PM
Kid_Roleplay
So I did this:

X Pos = X Pos + (speed*Cos(angle))
Y Pos = Y Pos - (speed*Sin(angle))

Only, now the diagonals aren't working right. As in the speeds are different, or rather slower, somehow than traveling strictly horizontally or vertically.
• 2nd September 2015, 10:24 PM
schrodinger
You have to store your Xpos and Ypos as alt. values and operate sin-cos calculations on that,
X and Y object's positions are pixel integers and won't work well with decimal operators (sin_cos)

start of frame >>
set Xpos_Val to X position
set Ypos_Val to Y position

on movement >>
set Xpos_Val to Xpos_Val + (speed*Cos(angle))
set Ypos_Val to Ypos_Val - (speed*Sin(angle))
set X position to Xpos_Val
set Yposition to Ypos_Val
• 2nd September 2015, 11:14 PM
Kid_Roleplay
That actually worked out quite well!

Now, however, the Move Safely thing gets stuck in walls, likely from attempting to read from X and Y values that have decimal points associated with them.
• 2nd September 2015, 11:40 PM
Kid_Roleplay
Got it all to work perfectly now, though I'm scared to think of how multiple objects will work.
• 3rd September 2015, 12:21 AM
DaveC
Move Safely has no issues with floating point movements, why would multiple objects be hard to implement? If you're storing the X/Y values in a value of the object you're moving, each object will be independent.
• 3rd September 2015, 01:16 AM
Kid_Roleplay
It's just that I'm going to be putting this to use in a game with some complicated movement and obstacle management. Move Safely crashes on me when I mess around with it, trying to understand how to put it to use, so it's just the daunting task I have ahead of me that I'm not so keenly looking forward to.

I wonder if there's an example around that uses the object extensively so I can see how it works when it comes to needing to check for collisions on multiple things (walls, projectiles, other enemies, jump plates, etc).
• 3rd September 2015, 01:38 AM
Tuna
I'd like to see an extensive example of Move Safely as well...

EDIT: actually, I think i realize now that this component doesn't MOVE the object, but only checks for collisions during a move...
• 3rd September 2015, 11:55 PM
Kid_Roleplay
I think it does that as well. I had tried something similar to it within code itself to try to keep collisions working right, where X and Y position were preserved while not overlapping an obstacle, and then an event further down where if the object was overlapping an obstacle, it'd set the X and Y positions back. Of course it didn't go as planned, which is why I'm looking into this object now. Problem is, I'd like to use it with objects that'd have a number of different movement types and collision circumstances, and I'm not sure where to place all of the events like Prepare, Commence, and Move out, because defined movement would be all over the place.
• 5th September 2015, 03:56 PM
Kid_Roleplay
Started implementing Move Safely little by little. It likes to crash a lot... And I'm not sure why.
• 6th September 2015, 02:55 AM
Kid_Roleplay
Now it's just getting aggravating. I have two objects now with the exact same collision code and very similar movement schemes. One works fine when hitting backdrops, and one does not. Yet both work perfectly fine when hitting obstacles that are Active Objects.

Do I need a separate Move Safely 2 Object per player/ enemy?
Show 40 post(s) from this thread on one page
Page 2 of 3 First 1 2 3 Last