Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

tuduf

6
Posts
5
Following
A member registered Jun 27, 2021

Recent community posts

Cool game! What is it written on?

as planned it will be a staff of wind :)

(1 edit)

Hey! Thank you very much for your help! The problem was in the wrong angle

RaycastHit2D[] hits = Physics2D.BoxCastAll(transform.position, new Vector2(attackRangeX, attackRangeY), 0f, transform.right, 2f, whatIsEnemies);
private void OnDrawGizmosSelected() {
		float angle = Util.GetAngleTowardsCursor(transform.position);
        Quaternion rotation = Quaternion.Euler(new Vector3(0f, 0f, angle - 90f));
		Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
        Gizmos.DrawWireCube(Vector3.right * 2f, new Vector2(attackRangeX, attackRangeY));
    }
public static float GetAngleTowardsCursor(Vector3 pos) {
	Vector3 mousePos = Input.mousePosition;
	mousePos.z = 5.23f;
	Vector3 objectPos = Camera.main.WorldToScreenPoint(pos);
		mousePos.x = mousePos.x - objectPos.x;
		mousePos.y = mousePos.y - objectPos.y;

float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
	return angle;
		}
(10 edits)

Hi! Here is my code http://p.tuduf.ru/UOtRtRc

If the enemy gets into the raycast, then it is clearly painted green, and with the cube otherwise, if I point the cursor at the enemy, it turns blue without entering the gizmo

public static Vector2 GetDirectionTowardsCursor(Transform baseTransform) {

var mouseWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);

return new Vector2(mouseWorld.x, mouseWorld.y) -

new Vector2(baseTransform.position.x, baseTransform.position.y);

}

public static Transform GetCharacterTransform()

{

return GetCharacter.transform;

}

I was able to move the pivot point, the rectangle rotates behind the cursor, but does not match the real raycast :(

RaycastHit2D[] hits = Physics2D.BoxCastAll(transform.position, new Vector2(attackRangeX, attackRangeY), 0f, transform.right, whatIsEnemies);

private void OnDrawGizmosSelected() { Gizmos.color = Color.green; Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one); Gizmos.DrawWireCube(Vector2.right * 2f, new Vector2(attackRangeX, attackRangeY)); }

and the usual raycast works correctly, the line goes from the center of the character to a right behind the cursor

Debug.DrawRay(transform.position, transform.right * max_distance, Color.green); RaycastHit2D[] hitCenter = Physics2D.RaycastAll(transform.position, transform.right * max_distance, 4f, whatIsEnemies);

I understand that I don’t understand anything at all

Hi! Thanks for the tutorial! How can you make a rotation not in the center of the cube, but at another point?