playMaker

Author Topic: Help/Question about Crosshair and hitpoint/raycast  (Read 686 times)

TicTac

  • Playmaker Newbie
  • *
  • Posts: 8
Help/Question about Crosshair and hitpoint/raycast
« on: October 14, 2021, 11:01:57 AM »
Hello,

(French to Google trad^^)
I am new to playmaker. (2 weeks)

I've been looking for 2 days to find a way to do something that seems simple to me; make a crosshair appear at the raycast hitpoint.
(different from a bullet hole since I want the crosshair to stay where the hitpoint is all the time as long as I press the aim key (mouse right))

I followed tutorials including those found on this forum but old for some and file, image missing.
I found on the net a script that does what i want but buggy because the position of the crosshair is often elsewhere from where it should be.
I tried to redo the script in fsm but...  ::)

I would like to do it by myself but I know that I would not succeed, the rest i can manage but here i am blocked.

My vision: raycast, store hitpoint, and spawn image at hitpoint. Easy...
But it's much more complicated than I imagine.

There is an action or way to make the image appear at the hitpoint?
Like an action:
Get picture (action fsm)
 enter where you want to spawn picture (var): hitpoint
 select image: drag and drop image.

I tried many things like tween ui position, drag and drop gameobject crosshair and set it. (but i don't really know what to change/to do)

Here is if anyone has a little time to put me on the track, thank you.
« Last Edit: October 14, 2021, 11:04:03 AM by TicTac »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Help/Question about Crosshair and hitpoint/raycast
« Reply #1 on: October 14, 2021, 01:12:11 PM »
Hi.
I.m not sure if i understand correctly, but i think you want something like this.

if the hit point is for example top left of the screen, the crosshair will move to that position (corsshair is on the UI Canvas)

if this is correct, then i believe you can achieve this with using 'World To Screen Point' or 'Rect Transform World To Screen Point'
Then use 'Rect Transform Set Local Position'



TicTac

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Help/Question about Crosshair and hitpoint/raycast
« Reply #2 on: October 14, 2021, 01:20:23 PM »
 Thanks to reply :)

To be a little more precise if I start from the Tuto hutong game.

When the raycast hits the cube then the crosshair is on the cube, if we move the cube up (y) the raycast hits the capsule and so the crosshair is on the capsule and so on if I aim for the ground, a wall etc.

TicTac

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Help/Question about Crosshair and hitpoint/raycast
« Reply #3 on: October 14, 2021, 02:56:03 PM »
I just tested.

World to screen point each time causes stack error on another fsm dedicated to aiming and if I uncheck the 2 actions it persists.

The rect transform world to screen point, and the rect transform set local position shows me the crosshair in the middle if I normalize or on the up right if I uncheck. My aim is much more to the left than the base center.

They don't display the crosshair at the hitpoint. I must do something wrong.

- Raycast
store hitpoint: hitpoint

- Rect transform world to screen point
Game objet : specify GO
                    crosshair
Camera: specify GO
             main camera
screen point: hitpoint
Normalize: check (middle of the screen) uncheck (right up of the screen)
every frame: check

- Rect transform set local position

game object: specify GO
                    crosshair

position: hitpoint
every frame check

TicTac

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Help/Question about Crosshair and hitpoint/raycast
« Reply #4 on: October 14, 2021, 05:41:48 PM »
Well...

I managed to make a big crosshair appear in my scene at the hitpoint but no way to have it ingame. It is doable but too difficult for me.
 I've seen an asset do basically what I want to do.

At first the red crosshair looks like what I would like to do but being fixed from the barrel of the rifle.
Difficult to do?

Otherwise, is it difficult to do my weapon to aim at the center of the screen?
(this one shoots projectiles which must suddenly pass through the center)

Because that's what I tried to do before but, for example, when I lower the aim towards the ground, the sight was on my head and the weapon draw much higher, thus not terrible.