Raycast from object to his own Vector3.forward

How can I make a bullet that draws a aycast from his position to his own Vector3 forward?

When I try to do it what I get is…
2541541--176572--upload_2016-3-6_18-8-7.png
Those are 4 instatiated bullets and the racast that should pint the direction they are facing.

Can you give me a clue about how to get the result I want.

The red vector is the one I want, and where I want to cast the ray along.

I hope you understand me.

“Forward” axis is the Z axis, the Z axis of your bullets points upwards (look at the gizmo at the top right as a reference), so when you raycast forward your bullets it raycasts upwards to the world.

Well, I knew it… I will illustrate it to make it clear heheheh

The red axis (X) is pointing to the right. Forward (Z) is the blue axis. Just remember: R for Red is R for Right.

Can you look at the second Image that I posted, I’m not actually trying to make the same vectors that are allready done. Im trying to make a ray that travels with the bullet and depends on the direction of the bullet itself.

Instead of using bulletTransform.forward as a direction for your raycast, use bulletTransform.right and it should work.

You should also seriously consider streamlining your prefabs/models so they make sens in the world they live in. Your bullets aren’t done the correct way… (and yes there is a correct way: forward means forward, if your bullet forward is on the X axis its sementically wrong, the day you’ll want to interact with third party plugins or have someone else work on your project it might not perform optimally, you’re also taking on bad habits that will later hinder your ability to work on other people’s projects)

SOLUTION:

    public Transform BulletPoint;

    void FixedUpdate()
    {
        Ray BulletRay = new Ray(transform.position, BulletPoint.forward * 25);
        Debug.DrawRay(transform.position, BulletPoint.forward*25 ,Color.red);
    }

Atach the script to the Trim of the bullet and on the BulletPoint atach the bullet.

Thanks for the tip.

But with 16 years old, I’m ok working alone :smile:

glad you figured it out, and good job on doing this at 16, i wish i had done the same :wink: