playMaker

Author Topic: Adjusting rotation to a moving object  (Read 2033 times)

...

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
Adjusting rotation to a moving object
« on: December 30, 2021, 06:10:32 PM »
Hi,

i'm having fun with a small card game. For moving cards i'm currently using Get Mouse X/Y, setting a vector 3, then converting screen to world point (mouse position to world position) and the i'm using move towards to move the card itself.

Move towards uses vector3.MoveTowards (trasform.position, targetPos, MaxSpeed.Value), so i'm interested how can i use those to achieve the effect of the card slowly rotating towards the movement point and then rotating back to zero.

For reference, you can go to 4:40 of the video ( hit 0.25 speed and watch how the card slowly rotates when being moved around the board.
« Last Edit: December 30, 2021, 06:55:51 PM by Fat Pug Studio »

...

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
Re: Adjusting rotation to a moving object
« Reply #1 on: December 30, 2021, 06:37:02 PM »
I tried subtracting vector3 position of the card (since it moves with a bit of delay) from vector3 position of the cursor, multiplying it a bit and applying x and y of the multiplied vector difference to x and y rotation of the card, but i'm afraid it's not good.

Maybe i can try getting current and last frame pointer position, subtract, multiply and apply to rotation, but that's a similar approach and i'm not sure it will work.

Or maybe a separate FSM with clamped object rotation by mouse.
« Last Edit: December 31, 2021, 01:39:10 AM by Fat Pug Studio »

...

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
Re: Adjusting rotation to a moving object
« Reply #2 on: December 31, 2021, 04:52:41 AM »
I tried the Mouse Look action, but it doesn't seem to do anything.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Adjusting rotation to a moving object
« Reply #3 on: December 31, 2021, 08:59:22 AM »
Hi.
Maybe by using some Float Smooth Damp or Float Smooth Damp Angle connected with the movement speed

and have empty parents for each rotation on the card.

But move towards might not have a velocity speed.
in one of my projects i made a version with velocity but its for 2d

i have attached it so you can have a look :)

...

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
Re: Adjusting rotation to a moving object
« Reply #4 on: January 03, 2022, 11:16:09 AM »
Thanks, i'll give it a go.