Answer the question
In order to leave comments, you need to log in
I can't figure out the input system. How to make movement without unity physics?
The bottom line is that I can not figure out the turns. The movement of the object was assigned to w and stuffed into FixedUpdate (), which hangs on the object itself. Now we need to implement the rotation on the buttons. That is, rotate the object in a circle when you press D (or S, if rotated in the opposite direction). With this, if you deal with it is not so difficult. That is, the question is more complicated, how can you implement the energy of an object without applying Rigidbody2D to it (and without using addForce(), respectively). I would also like to try to implement the logic without the MonoBehavior parent class, is it necessary to do this at all and what are the advantages? Paul rummaged through the Internet, but I did not find the answer to these questions, unfortunately.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity;
using UnityEngine.InputSystem;
public class Control : MonoBehaviour
{
private Actions inputs;
private Vector2 vector, rotate;
public void Awake()
{
inputs = new Actions();
}
public void Start()
{
inputs.Enable();
}
public void OnDisable()
{
inputs.Disable();
}
public void FixedUpdate()
{
this.gameObject.transform.position += new Vector3(vector.x * 0.1f, vector.y * 0.1f, 0);
this.gameObject.transform.Rotate(new Vector3(0,0,rotate.x*rotate.y));
}
public void OnMove(InputAction.CallbackContext context)
{
vector = context.ReadValue<Vector2>();
}
public void OnRotate(InputAction.CallbackContext context)
{
rotate = context.ReadValue<Vector2>();
}
}
Answer the question
In order to leave comments, you need to log in
For smoothness, you can use Mathf.Lerp, you can read about it here: https://docs.unity3d.com/ScriptReference/Mathf.Ler...
About MonoBehaviour: when working in Unity, you can’t get rid of it completely, because only scripts in which the class is inherited from MonoBehaviour. True, there are ECS plugins (an interesting thing, you can read about it on Google. I recommend LeoECS on my own), but even there, a “behavior” is used to initialize this all, so, as mentioned above, you can’t get rid of it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question