#Weapon sticks to sprite but I want it to rotate with my cursor

1 messages · Page 1 of 1 (latest)

past geyser
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponParent : MonoBehaviour
{
    public Vector2 PointerPosition { get; set; }          

    private void update()
    {
        transform.right = (PointerPosition-(Vector2)transform.position).normalized;

    }


}```
#

I think we try to change z of weapon with a vector 2 pointer position but I think vector 2 doesnt include z right?

#

It works in the video but in mine nothing happens

haughty pollen
past geyser
#

🤦

haughty pollen
#

pay attention. Case matters!

#

had you added a Debug.Log into that you would have seen that it is never executed. Big clue

past geyser
haughty pollen
#

So debug it. Actually look at the variables you are using rather than making assumptions

past geyser
haughty pollen
#

the one posted above

#

it's the only one I can see

past geyser
#

how should I write it?

haughty pollen
#

seriously?
Update not update

past geyser
#

oh okay

#

Now I can rotate the weapon but

#

How can I tell

#

Its in a big circle

haughty pollen
#

this

private void AnimateCharacter()
    {
        Vector2 lookDirection = pointerInput - (Vector2)transform.position;
        
    }

Is completely pointless, it does nothing

past geyser
#

okay so I'm deleting it

haughty pollen
#

why? You put it there for a reason didn't you?

past geyser
#

this channel does not write scripts from the beginning

#

so I copied the code made some changes but forgot to delete it

past geyser
haughty pollen
past geyser
#

😀

haughty pollen
#

look at your code!
lookDirection is a method local variable. It will affect nothing outside of it's enclosing method
as you do nothing with it. It in itself does nothing

#

this is basic C# of which you appear to know nothing

past geyser
#

youre right