hey guys im trying to solve a problem here, i’m trying to get the same position as the cube when i’m on it, so i can get dragged from one point to another, i tried to make my cube child of the ball but this is happening no parent-child relation
Imgur: The magic of the Internet with
parent child relation
Imgur: The magic of the Internet
script:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
using UnityEngine.EventSystems;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] GameObject Player;
Rigidbody playerRigidBody;
Vector3 movement;
Renderer playerColor;
[SerializeField] float speed = 10f;
[SerializeField] float jumpForce = 5f;
[SerializeField] bool hasJumpedOnce = false;
[SerializeField] Joystick joystick;
[SerializeField] GetAudioSource audioSFX;
Vector3 ballPosition;
// Start is called before the first frame update
void Start()
{
audioSFX = FindObjectOfType<GetAudioSource>();
playerRigidBody = Player.GetComponent<Rigidbody>();
playerColor = GetComponent<Renderer>();
hasJumpedOnce = false;
}
// Update is called once per frame
void Update()
{
HorizontalVerticalMovement();
}
public void JumpOnce()
{
if (hasJumpedOnce == false)
{
Vector3 jump = new Vector3(0, jumpForce, 0);
playerRigidBody.AddForce(jump, ForceMode.Impulse);
audioSFX.audioSource.PlayOneShot(audioSFX.jumpSFX, 5f);
hasJumpedOnce = true;
}
else
{
return;
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Ground")
{
hasJumpedOnce = false;
}
else if (collision.gameObject.tag == "WhiteCube")
{
hasJumpedOnce = false;
}
}
private void HorizontalVerticalMovement()
{
float verticalMovement = joystick.Vertical;
movement = new Vector3(0, 0, verticalMovement * speed);
playerRigidBody.AddForce(movement, ForceMode.Impulse);
float horizontalMovement = joystick.Horizontal;
movement = new Vector3(horizontalMovement * speed, 0, 0);
playerRigidBody.AddForce(movement, ForceMode.Impulse);
}
}