- Home /
How to influence the direction of an falling object by dragging?
Hi guys,
I was imagining a ball falling down with the camera attached right looking down aswell (basically the perspective of the ball). The gravity is of course easily created with a Rigidbody but now I was wondering how I can influence the vector the gravity is pointing at when I drag to the left for example.
Detailed example: On your smartphone you swipe to the left side and depending on how much you drag the ball changes his direction as well to the left. Same with all other directions and also it should not immediately change the direction but with a little break in between. If I remember correctly that is doable with a lerp.
Thanks a ton for your help, Cryttexx
Answer by Lazdude17 · Nov 01, 2019 at 04:05 AM
You wouldn't change the gravity vector, just add another force in the left or right direction. To make swipe length affect amount of movement. you need to calculate swipe length. Many youtube tutorials to show how to do this on touchscreen devices.
then you would just add this swipe length to your movement vectors calculation.
AddForce(swipeLength * moveSpeed, 0, 0)
Just to get you thinking on the right path. Hope it helps.
Thank you a lot for your answer. That was exactly what i was searching for and not giving me the code itself directly is a good idea because then i have to try around myself a bit aswell and that´s how you learn right? ^^ I didn´t think Unitys Rigidbody system enables to add diffrent forces and then calculates them to one summarized one itself. That´s pretty easy then
Your answer
Follow this Question
Related Questions
Where is the general Rigidbodies Drag? 3 Answers
Wrong gravity calculation? 2 Answers
Gliding vs bad acceleration dilema 0 Answers
Gravity suddenly started working very slowly 1 Answer
Why does my character fall slowly even though rigid.drag = 0? 1 Answer