- Home /
Arm passing through objects (Rotation - Rigidbody2D)
Hi. I have made a small game where you are supposed to move the Player with a Pickaxe, but my rotation on the arm and Pickaxe is passing through the wall (The Player is doing fine - I guess its because of the Rigidbody2D)
The problem is if I add a rigidbody2D to the Arm object it behaves on its own and is not a part of the Player (affected by gravity and shit etc.)
Here is a video of the problem link text
Here are pictures of Player01
And a picture of the Arm property
I feel like I have tried everything, but I don't know how to achieve proper collision with the Pickaxe and arm due to them not being able to have a Rigidbody2D
The code of the Arm Rotation
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArmRotation01 : MonoBehaviour {
float eulerMinRot = -70f;
float eulerMaxRot = 70f;
Vector3 currentEuler;
float rotationSpeed = 80f;
float rotation;
float myRotation;
bool facingRight;
PlayerController01 playerController01Script;
private void Awake()
{
playerController01Script = GameObject.FindObjectOfType<PlayerController01>();
}
// Update is called once per frame
void Update () {
rotation = Mathf.Clamp(rotation, eulerMinRot, eulerMaxRot);
if(Input.GetKey(KeyCode.W))
{
rotation += rotationSpeed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.S))
{
rotation -= rotationSpeed * Time.deltaTime;
}
transform.rotation = Quaternion.Euler(new Vector3(currentEuler.x, currentEuler.y, rotation));
}
private void LateUpdate()
{
//If the player is not facing right i would like to reverse the rotation so the that the arm and pickaxe doesnt go from + rotation on the z axis to - rotation on the z axis
if(playerController01Script.facingRight == false)
transform.rotation = Quaternion.Euler(new Vector3(currentEuler.x, currentEuler.y, -rotation));
}
}
Your answer
Follow this Question
Related Questions
How to keep the velocity of a rigidbody2d while changing its direction according to rotation? 1 Answer
setting transform physics2d issue 0 Answers
2D rigidbody velocity relative to rotation? 0 Answers
Rigidbody2d physic movement on 2d terrain. 0 Answers
In unity 2D c# how to rotate an object like geometry dash? 1 Answer