Help with instantiation and rotation

I’m trying to instantiate a slash facing the direction of the player, but I cant figure out how to rotate it properly.
if (Input.GetKey(KeyCode.Q) && f >= 100)
{
Instantiate(Slash, transform.position, transform.rotation);
f = 0;
}
Slash is the object, f is a timer.

You may be able to simply drive transform.forward (or transform.up when in 2D) equal to your movement vector, such as.

slashInstance.transform.up = vectorToPlayer;

NOTE: you must get slashInstance back from the Instantiate() call.

Otherwise, use Mathf.Atan2() to derive heading from cartesian coordinates:

Sine/Cosine/Atan2 (sin/cos/atan2) and rotational familiarity and conventions

Sorry, I’m pretty much brand new at this, how would I implement this in my code?

What part of what I suggested above are you struggling with?

At a minimum, understand how to receive a reference back from Instantiate and do further things with that instance. It’s the core of pretty much ANY Unity instantiate call.

I like this small step approach:

Imphenzia: How Did I Learn To Make Games:

If you run into trouble:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?