playMaker

Author Topic: Aligning moving objects[SOLVED]  (Read 3413 times)

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
Aligning moving objects[SOLVED]
« on: November 08, 2013, 12:28:09 PM »
Hello there,

I've just started using playMaker and I have to say it's pretty amazing! :)

I'm having a little bit of trouble aligning moving objects, however. I'm making a kind of endless runner/rhythm action game where prefab sections of the game environment are being spawned (or moved, I've tried both) in front of the player. The player stays still while the prefab sections move, kind of like a conveyer belt.

The problem is when I spawn or move the prefab sections they have a tendency to be just slightly behind the desired location, maybe 1 to 2 units out. I wouldn't normally consider this an issue, I'd just bump the spawn point forwards a few units to compensate. However because this is a rhythm action game the prefabs need to come in at exactly the right place or the audio will be off.

I've investigated a number of different approaches with no luck.

The issue lies in the prefab section moving as the next one is spawned. In the moment it takes for the CPU to figure out the place it should spawn and it actually spawning a slight misalignment is created. It's compounded by framerate and the speed at which the prefabs move (less frames, or quicker movement = bigger gaps).

Does anyone have a technique for solving a problem like this in playMaker/unity?
« Last Edit: November 14, 2013, 12:22:53 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Aligning moving objects
« Reply #1 on: November 11, 2013, 01:32:41 AM »
Hi,

 This is odd, 1 or 2 units is really a lot, are you positive it's not simple miscalculation? can you bring down the issue to a very minimum repro?

bye,

 Jean

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
Re: Aligning moving objects
« Reply #2 on: November 11, 2013, 04:15:49 AM »
Hi Jean, thanks for the reply.

As far as I can ascertain (from my similar thread over on the unity forums http://forum.unity3d.com/threads/209533-Aligning-moving-objects) it seems to be due to the fsm getting the spawn location on one frame but not setting the prefab to spawn at that location until the next frame, by which time it's out of date, resulting in misalignment.

This could be wrong, but it seems to make vague sense from my extensive investigations so far.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Aligning moving objects
« Reply #3 on: November 12, 2013, 02:11:48 AM »
Hi,

 then, have your placement logic don ein the prefab itself at th etime of spawning ( let the prefab position itself basically).

 have you tried that?

bye,

 Jean

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
Re: Aligning moving objects
« Reply #4 on: November 12, 2013, 06:41:07 AM »
Seemingly even then it places the prefab just behind where it should be.

I understand why that should work though; if it's being set to its position on the frame it spawns rather than the frame before it should be the most up-to-date position.

I have each prefab getting the position on every frame, then setting the position in the same state with no improvement. It seems like there may even be some lag between actions in the stack that causes the misalignment.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Aligning moving objects
« Reply #5 on: November 12, 2013, 08:14:15 AM »
Hi,

 How do you compute the position you want to set? This is maybe the problem? I cna't really understand how within one frame you have a x unity offset, that's huge. what are the scale of your objects?

bye,

 Jean

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
Re: Aligning moving objects
« Reply #6 on: November 12, 2013, 09:02:34 AM »
I have tried many different methods.

What I would like to do is give each prefab a spawn helper as a child so the next prefab that spawns in can use it's location to spawn in.

To do this I have a trigger get the tag of the helper once it has spawned, that is then stored as a variable. When a new prefab spawns it gets the helpers position and set's its own position to it. Underneath that in the stack I have an itween move to action to a vector behind the player (0,0,-240). Once it reaches this location it despawns and sends an event to spawn the next section.

I'm pulling my hair out a little bit trying to figure out a way to do it to be honest! I've now tried so many different variations on this approach without any success.

The scale of the sections I'm spawning in are w:22 h:22 d:240 and they move at a speed of '60'. I have set it up this way so the sections move at 60 beats per minute. If I increase the speed I increase the bpm - this is important for the rhythm part of my game.

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
Re: Aligning moving objects
« Reply #7 on: November 13, 2013, 12:02:06 PM »
So I managed to solve this by having only the first prefab of the sequence control the movement. When another prefab spawns in behind it it gets parented to the first prefab. Once the first prefab reaches a certain point (behind the player) the next prefab becomes the leader and controls movement, the first prefab then gets despawned and the next prefab in line it becomes the child of the new leader, and so on.

If anyone comes across this problem in the future send me a PM and I'll explain in more detail :)