using System.Collections; using System.Collections.Generic; using UnityEngine; public…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Player : MonoBehaviour { public float speed = 5f; // Speed of character movement
codeprivate Animator anim; private void Start() { anim = GetComponent<Animator>(); } void Update() { // Move character based on input axes float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); // Calculate movement direction Vector2 movement = new Vector2(horizontalInput, verticalInput) * speed * Time.deltaTime; // Apply movement to the character’s position transform.Translate(movement); anim.SetFloat("moveX", movement.x); anim.SetFloat("moveY", movement.y); }} make it so if the player is moving right (D key or right arrow) and has the knife game object, the knifes transform will be set to (0.41, -0.02, 0) and in the sprite renderer the "Flip" component will be set to false. And if the player is moving left (A key or left arrow) and has the knife game object, the knifes transform will be set to (-0.41, -0.02, 0) and in the sprite renderer the "Flip" component will be set to true
- Assistant
- User
the position of the knife and the sprite renderer component did not change
- Assistant
Apologies for the confusion. It seems that the issue is with the local position value being set on the knife transform. Local position is relative to the parent object, so we need to use the parent's transform instead of the knife's transform to calculate the correct position.
- User
if (knife != null) change this line to say if the player has the knife set as its child and is moving
- Assistant
- User
the knife is a pick up item, so make it so these same conditions are met if the player picks up the knife
- Assistant