playMaker

Author Topic: Object moving on fixed height of Raycast vector [SOLVED]  (Read 1183 times)

marvoc

  • Playmaker Newbie
  • *
  • Posts: 37
Object moving on fixed height of Raycast vector [SOLVED]
« on: April 09, 2019, 06:12:03 AM »
Hi all :)
I have one specific problem.
As you can see on picture Im raycasting from camera to player unit (blue hexagon) and then it continues.
Id like to have a sphere (red circles, there are two of them as to be 2 examples) which will move with vector.

This could be done (I suppouse) when Ill take direction vector somewhere on that raycast, lerp it and set it as position for the sphere.
First time I through Ill use 50% lenght of raycast between terrain and camera, but it will not work. Height is different in each position.

But I need to have sphere on exact height. Let say 30m from world origin. Never will go +/- Y. But should move in X and Z.

Why Im using raycast from camera through model? Because Im using air and groud units and from player point of view (is it shoot em up game) is this solutinon more precise then to have only colliders. Then is different angle when is it on bottom or on top of the screen.
« Last Edit: April 10, 2019, 04:46:52 PM by marvoc »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Object moving on fixed height of Raycast vector
« Reply #1 on: April 09, 2019, 08:05:59 AM »
Hi.
Maybe you can set a invisible collider(set as trigger) on the height that you want the circle to stay give it a separate layer.

Then use a 2nd raycast to the same direction as the first, but it should only detect the invisible collider(set as trigger) layer.
Get the hit point and set the sphere to that position.

i did not test, but i think this should work.

marvoc

  • Playmaker Newbie
  • *
  • Posts: 37
Re: Object moving on fixed height of Raycast vector
« Reply #2 on: April 09, 2019, 08:11:52 AM »
ooohhh It should work! thanks Ive already had something like this thanks for flight level of the planes ;) but with different shape.
it is a cool idea! Ill tell you if it is working or not.

martin

marvoc

  • Playmaker Newbie
  • *
  • Posts: 37
Re: Object moving on fixed height of Raycast vector
« Reply #3 on: April 10, 2019, 04:46:30 PM »
So it is working :) thanks

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Object moving on fixed height of Raycast vector [SOLVED]
« Reply #4 on: April 10, 2019, 06:32:33 PM »
Hi.
Np happy to help :)