K
K
KraGen.Developer2021-08-30 23:20:10
Unity
KraGen.Developer, 2021-08-30 23:20:10

How to implement the movement of a 3D ball through AddForce on Android?

Hello, for about two days now I can not implement the movement of the sphere through AddForce using the UI joystick. I'm making a game for android and I need the sphere to move along the camera's view vector. I don’t know what to do anymore, where to write with the Docks unit, I reviewed this Rigidbody, it seems like nothing helps me (or I didn’t look at it).
6In general, according to my idea, the sphere should move through this:

rb.AddForce(transform.forward * joystick.Vettical * speed,0f,transform.right * joystick.Horizontal * speed);

Through another script, the sphere was directed along the camera's gaze vector. And in theory it should work, only here
rb.AddForce(transform.forward * joystick.Vettical * speed,0f,transform.right * joystick.Horizontal * speed) does not work. Anyone who has come across this or similar or knows how to solve this problem in a different way, please help, because I don’t know what to do anymore, the brain is boiling.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Spartanec33, 2021-08-31
@KraGenDeveloper

I think it's worth checking whether something other than zero is transmitted when interacting with the joystick.
change axles here

rb.AddForce(transform.forward * joystick.Vettical * speed,0f,transform.right * joystick.Horizontal * speed);

and if you want to in the direction of the camera, then I think you can
rb.AddForce(_camera.transform.right.x * joystick.Horizontal * speed, 0f, _camera.transform.forward.z * joystick.Vettical * speed)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question