playMaker

Author Topic: set velocity 2d issue  (Read 1632 times)

misterjuly

  • Sr. Member
  • ****
  • Posts: 357
set velocity 2d issue
« on: April 11, 2023, 09:32:18 PM »
Hello,

I am moving a game object back and forth with set velocity 2d. I am moving it one direction x amount and moving it the other direction -x amount. It seems that sometimes over time the overall average position of the game object moves one direction or another. Is this a float precision problem or a set velocity 2d problem or a rigid body problem? How do I fix this? Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: set velocity 2d issue
« Reply #1 on: April 12, 2023, 06:38:20 AM »
hi,
are you moving it with a controller?

are you using Physics materials (for bounce / friction)?

misterjuly

  • Sr. Member
  • ****
  • Posts: 357
Re: set velocity 2d issue
« Reply #2 on: April 12, 2023, 09:38:02 AM »
It is not my main character; it is just a game object in the environment that I am moving back and forth (so, if I understand you correctly, I am not using a controller). I am not using any physics materials on it.

Thanks!

misterjuly

  • Sr. Member
  • ****
  • Posts: 357
Re: set velocity 2d issue
« Reply #3 on: April 12, 2023, 09:47:07 AM »
I tried putting a physics material 2d on, with different friction settings, but it didn't seem to do anything. I should note that the only colliders these objects have are triggers, not solid colliders. Hopefully that gives you more information. Thanks!

John Bassi

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: set velocity 2d issue
« Reply #4 on: April 12, 2023, 10:41:33 AM »
Hi.
velocity is not reliable if you want to move point a/b if you would set it over time.

if you need to velocity for some reason then you could set 2 triggers (pos 1 / pos 2)
and check for the triggers to stay between them

if you do not need velocity, try 'Tween Position'

misterjuly

  • Sr. Member
  • ****
  • Posts: 357
Re: set velocity 2d issue
« Reply #5 on: April 12, 2023, 07:06:52 PM »
A couple problems. One, if I use triggers, I have to have a bunch more game objects with triggers on it. I can do that, but it would be a pain. Two, with tween position I need to change both x and y axis at different rates. It is also tedious to set different positions vs. just setting a generic force or velocity. Is add force more reliable? Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: set velocity 2d issue
« Reply #6 on: April 13, 2023, 07:06:21 AM »
Hi.
Do not use force continues it is very cpu heavy.

I use a prefab "mover" which has a parent and 2 children for position 1 and position 2

On the parent I have a fsm for the tween where I expose a game object variable where in can drag and drop the item I want to move.
I have some other variables exposed for time and other settings.
This way I can reuse it on several objects