Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TheBlackHorse |
Hello!
So I am trying to make a card game and I am using a raycast to spawn a card (3d sprite) on my gameboard (rigidbody). Now I want these cards to spawn alligned on a grid, how could I make these?
This is my code:
var camera = get_tree().get_root().find_node("Camera", true, false)
if Input.is_action_just_released("leftclick") && cardinhand == 1 :
var space_state = get_world().direct_space_state
var mouse_position = get_viewport().get_mouse_position()
rayOrigin = camera.project_ray_origin(mouse_position)
rayEnd = rayOrigin + camera.project_ray_normal(mouse_position) * 2000000000
var intersection = space_state.intersect_ray(rayOrigin, rayEnd)
if not intersection.empty():
board = 1
var addcard = card.instance()
addcard.Cardname = cardnm
add_child(addcard)
addcard.translation = Vector3(intersection.position.x*1.01,intersection.position.y,intersection.position.z)
Also a screenshot of my nodes since I am not really sure that I have placed the grid correctly: Screenshot by Lightshot