playMaker

Author Topic: Moving an object accurately one unit at any speed[SOLVED]  (Read 3334 times)

MattyWS

  • Junior Playmaker
  • **
  • Posts: 79
    • View Profile
Moving an object accurately one unit at any speed[SOLVED]
« on: February 15, 2018, 01:38:28 PM »
Hi!

This isn't so much me asking for help, in fact it's the opposite. A long time ago I made a game in a weekend using playmaker for fun called Ricochet. It's on the android store here;

https://play.google.com/store/apps/details?id=com.EarlyGames.Ricochet&hl=en

However I abandoned the project before making more levels because of a game breaking bug. I was using physics on the ball to move it, initially and using collisions with the bars and the ball to make the ball bounce. At first I thought this was a solid way of doing it. What could go wrong? The bar was exactly 45 degrees and the ball starts off aligned to an imaginary grid with the bars, everything was placed perfectly.

Well, the ball would very rarely not collide exactly on time with the bars and would eventually become offset, which would then make the ball collide incorrectly and it would bounce off at a random angle. I was a noob at the time so this was a big problem I couldn't solve.

Enter today! I was thinking about the project today and it clicked, I could just manually move the ball exactly 1 unit, check whats there then move 1 unit accordingly, repeat. This removes physics in favour of just using translate. I'd move the ball for 0.5 seconds at a speed of 2 if I wanted it to be double the speed. Unfortunately for me once again, this wasn't accurate. As it turns out the ball would sometimes stop too late, becoming slightly offset once again. :(

My next attempt was to look for something other than moving it with physics or translate so I tried a using iTween actions and BAM! No matter how fast I wanted to make the ball, it would move exactly 1 unit, do it's check then move again accordingly. It all happens instantly so the ball looks like it's smoothly moving. So I've solved the issue (mind you I need to start my project again as I no longer have that project on my pc).

I guess my main point in this thread is for one, to help others come to the same realisation that using standard methods to move objects in Unity are flawed and inaccurate. And secondly, I guess I want to ask why they're inaccurate? How have other people done similar things without noticing this flaw?

Anyway, expect to see Ricochet 2 released on PC in the future. :) Pure Playmaker game. Now that I've become a little more educated on game design I will also strive to make the game a little more balanced with difficulty, since almost everyone stopped playing around level 6-9 due to my ramp in difficulty throughout the 27 levels. :P

Thanks,
MattyWS
« Last Edit: February 22, 2018, 03:32:21 AM by jeanfabre »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5194
    • View Profile
    • jinxtergames
Re: Moving an object accurately one unit at any speed
« Reply #1 on: February 15, 2018, 04:06:18 PM »
Hi.
Thx for this explanation, maybe you can show off some fsms while building it.

But i would suggest using DOTween instead of itween as itween is outdated and slow.

MattyWS

  • Junior Playmaker
  • **
  • Posts: 79
    • View Profile
Re: Moving an object accurately one unit at any speed
« Reply #2 on: February 15, 2018, 04:32:43 PM »
Hi, I may have spoke too soon, the more actions I add to each step (more collision checks) the more the ball starts to visually stutter. :( I will try DOTween and see if this is any faster but I fear the stutter is within the Trigger2D Event actions, there's currently 3 of those within a state. I guess back to the drawing board! If you wannt to do too much per step then it won't look good (it will work though).

EDIT: I just removed all trigger events and just used Next Frame Event, it still stutters, so I guess there's a chance that it is iTween. I will double check this.
« Last Edit: February 15, 2018, 04:35:24 PM by MattyWS »

MattyWS

  • Junior Playmaker
  • **
  • Posts: 79
    • View Profile
Re: Moving an object accurately one unit at any speed
« Reply #3 on: February 16, 2018, 06:34:15 AM »
I tested DOTween free with the free playmaker actions and it seems a lot smoother, however I was getting issues trying to loop the whole thing. Is the DOTween pro package and the $10 playmaker actions for DOTween on the asset store worth it or am I good to stick with the free stuff? is the free actions still supported?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5194
    • View Profile
    • jinxtergames
Re: Moving an object accurately one unit at any speed
« Reply #4 on: February 16, 2018, 07:54:26 PM »
Hi.
To be honest i don't use tweens much, most things i do with animation/animator.
I think the free actions are still supported, i can see that his last post on that topic was Jan 8 2018 :)

the paid version last update was Nov 22, 2016

MattyWS

  • Junior Playmaker
  • **
  • Posts: 79
    • View Profile
Re: Moving an object accurately one unit at any speed
« Reply #5 on: February 18, 2018, 11:52:15 AM »
Hi again, So I have a new problem now with 2D trigger events, it seems the actions don't function but there's no errors. I seem to recall a long time ago that there was a special object that needed to be in the scene at all times for 2D stuff to work but I can't find that anywhere, and now the 2D actions seem built into the playmaker package.

My objects are set to be triggers, have circle colliders and have a 2d rigidbody set to static., they re also using tags to like "player" and "bar01" etc. The actions just get ignored. :( Anyone know the reason?

EDIT: Also is there any way to check if there's no trigger events happening? As in, if the ball moves a unit, checks and finds that nothing is there, I want to have it repeat the action and move another space, but if it does find something, move to the next state which checks which trigger event
« Last Edit: February 18, 2018, 11:56:55 AM by MattyWS »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5194
    • View Profile
    • jinxtergames
Re: Moving an object accurately one unit at any speed
« Reply #6 on: February 18, 2018, 12:33:30 PM »
Hi.
Quote
Hi again, So I have a new problem now with 2D trigger events, it seems the actions don't function but there's no errors. I seem to recall a long time ago that there was a special object that needed to be in the scene at all times for 2D stuff to work but I can't find that anywhere, and now the 2D actions seem built into the playmaker package.
I think that the object you are talking about, is not needed anymore.

i did a quick test and all seems to work.
Is the collider size large enough and did you check 'is trigger'

Quote
is there any way to check if there's no trigger events happening? As in, if the ball moves a unit, checks and finds that nothing is there, I want to have it repeat the action and move another space, but if it does find something, move to the next state which checks which trigger event

i don't think that there is, but maybe you can use raycast instead.

There is an action called "Raycast2" on the Ecosystem that has a no hit event


MattyWS

  • Junior Playmaker
  • **
  • Posts: 79
    • View Profile
Re: Moving an object accurately one unit at any speed
« Reply #7 on: February 18, 2018, 01:01:13 PM »
I resolved my first issue and 2d trigger events occur now, I tried the raycast 2 action it seems to not detect anything.

so now, my ball starts moving one unit, moved the the next state which is the raycast2 with events Yes and No (Hit Event = yes, No Hit Event = no), no gos back to the previous state, yes goes to a state which checks for trigger events. However it never chooses yes. Could this be because the colliders in question are triggers? Or is the Raycast2 simply using world space coordinates?


I added an image of the balls graph. As you can see, on the left is the states for each direction the ball is moving in, once it's moved, it checks for collisions (raycast2) then either goes back or goes to trigger events if needed. On the right, it basically has trigger events to say what it has collided with and which direction the ball should move next.

The only thing not working here is the middle section, raycast2
« Last Edit: February 18, 2018, 01:09:20 PM by MattyWS »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5194
    • View Profile
    • jinxtergames
Re: Moving an object accurately one unit at any speed
« Reply #8 on: February 18, 2018, 04:01:50 PM »
Hi,
Ah sorry, i will need a 2D version i guess.
i will make 1 for you tomorrow (midnight here atm)

MattyWS

  • Junior Playmaker
  • **
  • Posts: 79
    • View Profile
Re: Moving an object accurately one unit at any speed
« Reply #9 on: February 19, 2018, 03:40:11 AM »
Ahh I just assumed it was a 2D action, my bad for not stating fully that this was completely using 2D colliders.

You would be a life saver if you made a 2D version! It's the only thing holding back the full functionality of this. :) I'm actually quite surprised there wasn't already an action to check if whether or not there is a collision/trigger event. It seems like the kind of action that would be really handy. :)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5194
    • View Profile
    • jinxtergames
Re: Moving an object accurately one unit at any speed
« Reply #10 on: February 19, 2018, 04:22:26 PM »
Hi.
I totally forgot to make the action (doing overtime @ work)
I will do it tomorrow, again sorry for the delay  :-[

MattyWS

  • Junior Playmaker
  • **
  • Posts: 79
    • View Profile
Re: Moving an object accurately one unit at any speed
« Reply #11 on: February 20, 2018, 01:41:47 AM »
Hey, don't apologise, it's on your own time. :) It's not like I can force you to even do anything and I very much appreciate the helping hand! :D

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5194
    • View Profile
    • jinxtergames
Re: Moving an object accurately one unit at any speed
« Reply #12 on: February 20, 2018, 04:02:20 PM »
Hi,
Can you try the attachment below

MattyWS

  • Junior Playmaker
  • **
  • Posts: 79
    • View Profile
Re: Moving an object accurately one unit at any speed
« Reply #13 on: February 20, 2018, 04:39:06 PM »
Hey, took me a while to figure out why this wasn't working until I realised the object I was using this on (the ball) was being counted as a collision? When the ball had it's own circle collider it moved one unit, found a collision and moved to the next stage. But when I remove the collider from the ball it will continue without detecting it's self.

The problem with removing the balls own collider is once it gets to a bar, it can't actually collide with it to say what direction to move next. Is it possible to exclude it's self from this check? Or exclude tags? The problem in this case with including tags is there may be more than one tag to collide with. Of course, if I ever have 2 balls in play with the same tag (player)if they ever cross over they will stop. :(

My case is quite specific. I will probably be able to state if a collision is found, check if it's a ball, then keep moving the same direction. However if it's finding it's own collision then moving on to check collisions, it wont find anything and the ball will stop.
« Last Edit: February 20, 2018, 04:47:41 PM by MattyWS »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5194
    • View Profile
    • jinxtergames
Re: Moving an object accurately one unit at any speed
« Reply #14 on: February 21, 2018, 12:00:42 AM »
Hi,
there are a few ways to go about this.

You can make an empty object and move the position just outside the ball position
but due to that it is a ball that probably rolls you need to make a parent to move the ball and inside it the ball needs to be rotated and the empty object for the raycast position.
Which needs some math to get it right.

You can use the layer mask and if you have multiple players that you also want to detect call the layers player 1, player 2 and so on.
tag can stay as "player"

You can also detect everything and then loop thru an array or check tag if it is a player or wall (or enemy or anything else)
and then do what is needed.