torso turning and ray casting
This commit is contained in:
parent
9d0bf18030
commit
3235ac5a23
@ -5,6 +5,10 @@
|
||||
|
||||
[node name="Body Builder Menu" type="Spatial"]
|
||||
script = ExtResource( 2 )
|
||||
torsoPath = NodePath("Torso")
|
||||
cameraPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/Camera")
|
||||
rayCastPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/MouseLook")
|
||||
viewPortPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport")
|
||||
|
||||
[node name="GUI" type="MarginContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
@ -66,4 +70,7 @@ render_target_update_mode = 3
|
||||
[node name="Camera" type="Camera" parent="GUI/HBoxC/ViewportContainer/Viewport"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3 )
|
||||
|
||||
[node name="MouseLook" type="RayCast" parent="GUI/HBoxC/ViewportContainer/Viewport"]
|
||||
enabled = true
|
||||
|
||||
[node name="Torso" parent="." instance=ExtResource( 1 )]
|
||||
|
@ -1,20 +1,33 @@
|
||||
extends Spatial
|
||||
|
||||
export(NodePath) var torsoPath
|
||||
export(NodePath) var cameraPath
|
||||
export(NodePath) var rayCastPath
|
||||
export(NodePath) var viewPortPath
|
||||
|
||||
const ROT_MOD = 500
|
||||
const ROT_DECLINE = 0.1
|
||||
|
||||
var _viewRot = false
|
||||
var _prev_mouse_pos
|
||||
var _camera : Camera
|
||||
var _rayCast : RayCast
|
||||
var _torso : RigidBody
|
||||
var _viewport : Viewport
|
||||
|
||||
var _velx = 0
|
||||
var _vely = 0
|
||||
|
||||
var _torso : RigidBody
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
PhysicsServer.area_set_param(get_viewport().find_world().get_space(), PhysicsServer.AREA_PARAM_GRAVITY, 0)
|
||||
_torso = get_node("Torso")
|
||||
_torso = get_node(torsoPath) as RigidBody
|
||||
_camera = get_node(cameraPath) as Camera
|
||||
_rayCast = get_node(rayCastPath) as RayCast
|
||||
_viewport = get_node(viewPortPath) as Viewport
|
||||
|
||||
|
||||
func _process(delta):
|
||||
if _viewRot:
|
||||
@ -40,32 +53,24 @@ func _process(delta):
|
||||
_vely *= decline
|
||||
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
pass
|
||||
# Get the camera
|
||||
#var camera = get_node("GUI/HBoxC/ViewportContainer/Viewport/Camera")
|
||||
if _viewRot:
|
||||
var mouse_pos = _viewport.get_viewport().get_mouse_position()
|
||||
|
||||
#var mouse_pos = get_viewport().get_mouse_position()
|
||||
#set origin of rayCast
|
||||
var orig = _camera.project_ray_origin(mouse_pos)
|
||||
|
||||
# Project mouse into a 3D ray
|
||||
#var ray_origin = camera.project_ray_origin(mouse_pos)
|
||||
#var ray_direction = camera.project_ray_normal(mouse_pos)
|
||||
#set cast_to of rayCast
|
||||
_rayCast.translation = orig
|
||||
_rayCast.cast_to = orig + _camera.project_ray_normal(mouse_pos) * 1000.0
|
||||
|
||||
# Cast a ray
|
||||
#var from = ray_origin
|
||||
#var to = ray_origin + ray_direction * 1000.0
|
||||
#var space_state = get_world().get_direct_space_state()
|
||||
#var hit = space_state.intersect_ray(from, to)
|
||||
if _rayCast.is_colliding():
|
||||
# collider will be the node hit
|
||||
print(_rayCast.get_collider())
|
||||
|
||||
#print("test")
|
||||
|
||||
#if hit.size() != 0:
|
||||
# collider will be the node you hit
|
||||
#print(hit.collider)
|
||||
#pass
|
||||
|
||||
func _input(event):
|
||||
if _viewport.get_viewport().get_mouse_position().x >= 0:
|
||||
if event is InputEventMouseButton:
|
||||
if event.pressed:
|
||||
print("Mouse Click at: ", event.position)
|
||||
|
Loading…
x
Reference in New Issue
Block a user