Question by
overbaal · Feb 09 at 02:55 PM ·
movementgameobjecttransformposition
how can I move an object around a parent object manually?
Greetings, I am looking for a way to move a pointer or pointer around the player which I will manage with touch. So far I have tried to do it in the following way, but I don't know if it is the right one. I hope you can help me, greetings and thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class CosSin : MonoBehaviour
{
[SerializeField]
private int _amplitude = 1;
[SerializeField]
private float _frequency = 0.1f;
private PlayerInput playerInput;
private float posY = 0, posX = 0;
private float lastY = 3, lastX;
private void Start()
{
playerInput = GetComponentInParent<PlayerInput>();
}
private void Update()
{
Vector2 posicion = playerInput.actions["Apuntador"].ReadValue<Vector2>();
Debug.Log(posicion);
if(Mathf.Abs(posicion.x) > 0.1f && Mathf.Abs(posicion.y) > 0.1f) {
float x = Mathf.Cos(posicion.x * _frequency) * _amplitude;
float y = Mathf.Sin(posicion.y * _frequency) * _amplitude;
transform.position = new Vector2(x, y);
lastX = x;
lastY = y;
}
transform.localPosition = new Vector2(lastX, lastY);
}
}
Check this video for more details: link text
Comment
Your answer
Follow this Question
Related Questions
How to properly make an object follow the edge of another object? 0 Answers
How to find the transform position of another gameobject then move a gameobject to that position? 1 Answer
GameObject not looking at me.. 1 Answer
Move Character in the way he is facing.,Make character move in way he is facing. 1 Answer