- Home /
instantiate an object on the intersection point between two objects on the x and y axis
I'm creating a Spider-Man type of web-swinging game for myself and I need some help on creating the web connector point. Right now when I click the G key, I fire a RayCast from my player towards an object in front of me, it creates the web connection point, and I swing toward it. What I need to do however is to take the current player position upon firing the RayCast, and take the hit point of the RayCast, and find what the intersection point in front of me on the X and Z axis would be (so I can instantiate the web connector on that position with the y being the same as the hit point). How should I do this?
Answer by Wolfie · Sep 27, 2018 at 12:52 AM
I'm a little bit confused as to what you're trying to achieve. Are you trying to fire the web into an arbitrary space off the top of the screen? If so then RaycastHit contains information on the point where the raycast intersects a collider, so if you're trying to get the central point between your raycast target and the player then just average the positions of the RaycastHit and the player's own position in world space to get the midpoint, manually increase the y value and then shoot a web towards that new point. That should mean you're always swinging from a midpoint rather than firing a web like a grappling hook.