Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Spatial
- export var speed = 10
- var x_rotation = 0
- var m_vPosition = Vector3()
- var m_vView = Vector3()
- var m_vUpVector= Vector3(0,1,0)
- var m_vStrafe= Vector3()
- export var turnSpeed=1.5
- var isRun=false
- var isShoot=false
- var isJump=false
- func Cross( vVector1, vVector2):
- var vNormal= Vector3()
- vNormal.x = ((vVector1.y * vVector2.z) - (vVector1.z * vVector2.y))
- vNormal.y = ((vVector1.z * vVector2.x) - (vVector1.x * vVector2.z))
- vNormal.z = ((vVector1.x * vVector2.y) - (vVector1.y * vVector2.x))
- return vNormal
- func Magnitude( vNormal):
- return sqrt( (vNormal.x * vNormal.x) +
- (vNormal.y * vNormal.y) +
- (vNormal.z * vNormal.z) )
- func Strafe( speed):
- m_vPosition.x += m_vStrafe.x * speed
- m_vPosition.z += m_vStrafe.z * speed
- m_vView.x += m_vStrafe.x * speed
- m_vView.z += m_vStrafe.z * speed
- func Move( speed):
- var vVector = m_vView - m_vPosition
- m_vPosition.x += vVector.x * speed
- m_vPosition.z += vVector.z * speed
- m_vView.x += vVector.x * speed
- m_vView.z += vVector.z * speed
- func Normalize( vVector):
- var magnitude = Magnitude(vVector)
- vVector = vVector / magnitude
- return vVector
- func Rotate( angle, x, y, z):
- var vNewView = Vector3()
- var vView = m_vView - m_vPosition
- var cosTheta = cos(deg2rad(angle))
- var sinTheta = sin(deg2rad(angle))
- vNewView.x = (cosTheta + (1 - cosTheta) * x * x) * vView.x
- vNewView.x += ((1 - cosTheta) * x * y - z * sinTheta) * vView.y
- vNewView.x += ((1 - cosTheta) * x * z + y * sinTheta) * vView.z
- vNewView.y = ((1 - cosTheta) * x * y + z * sinTheta) * vView.x
- vNewView.y += (cosTheta + (1 - cosTheta) * y * y) * vView.y
- vNewView.y += ((1 - cosTheta) * y * z - x * sinTheta) * vView.z
- vNewView.z = ((1 - cosTheta) * x * z - y * sinTheta) * vView.x
- vNewView.z += ((1 - cosTheta) * y * z + x * sinTheta) * vView.y
- vNewView.z += (cosTheta + (1 - cosTheta) * z * z) * vView.z
- m_vView = m_vPosition + vNewView
- transform=transform.rotated(Vector3(x,y,z),deg2rad(angle))
- # Called when the node enters the scene tree for the first time.
- func _ready():
- $MeshInstance.addAnimation("stand", 0, 39, 9)
- $MeshInstance.addAnimation("run", 40, 45, 10)
- $MeshInstance.addAnimation("attack", 46, 53, 10)
- $MeshInstance.addAnimation("pain_a", 54, 57, 7)
- $MeshInstance.addAnimation("pain_b", 58, 61, 7)
- $MeshInstance.addAnimation("pain_c", 62, 65, 7)
- $MeshInstance.addAnimation("jump", 66, 71, 7)
- $MeshInstance.addAnimation("flip", 72, 83, 7)
- $MeshInstance.addAnimation("salute", 84, 94, 7)
- $MeshInstance.addAnimation("fallback", 95, 111, 10)
- $MeshInstance.addAnimation("wave", 112, 122, 7)
- $MeshInstance.addAnimation("point", 123, 134, 6)
- $MeshInstance.addAnimation("crouch_stand", 135, 153, 10)
- $MeshInstance.addAnimation("crouch_walk", 154, 159, 7)
- $MeshInstance.addAnimation("crouch_attack", 160, 168, 10)
- $MeshInstance.addAnimation("crouch_pain", 169, 172, 7)
- $MeshInstance.addAnimation("crouch_death", 173, 177, 5)
- $MeshInstance.addAnimation("death_fallback", 178, 183, 7)
- $MeshInstance.addAnimation("death_fallbackforward", 184, 189, 7)
- $MeshInstance.addAnimation("death_fallbackslow", 190, 197, 7)
- $MeshInstance.addAnimation("boom", 198, 198, 5)
- $MeshInstance.setAnimationByName("stand")
- m_vPosition = transform.origin
- func _process(delta):
- var vCross = Cross(m_vView - m_vPosition, m_vUpVector)
- m_vStrafe = Normalize(vCross)
- var kspeed =speed * delta
- if Input.is_action_pressed("up") :
- Move(kspeed)
- $MeshInstance.setAnimationByName("run")
- #$MeshInstance.SetAnimationRollOverByName("run","stand")
- isRun=true
- if Input.is_action_pressed("turn_left") :
- Rotate(-turnSpeed, 0, 1, 0)
- if Input.is_action_pressed("turn_right") :
- Rotate(turnSpeed, 0, 1, 0)
- else:
- if Input.is_action_pressed("shoot") :
- #$MeshInstance.SetAnimationRollOverByName("attack","stand")
- $MeshInstance.setAnimationByName("attack")
- isShoot=true
- else:
- if Input.is_action_pressed("jump") :
- $MeshInstance.SetAnimationRollOverByName("jump","stand")
- isJump=true
- else:
- if Input.is_action_just_released("up") :
- isRun=false
- if not isShoot and not isJump and not isRun:
- #print($MeshInstance.get_Current_frame())
- $MeshInstance.setAnimationByName("stand")
- pass
- if isJump:
- if $MeshInstance.get_Current_frame()>=71:
- isJump=false
- if isShoot:
- if $MeshInstance.get_Current_frame()>=53:
- isShoot=false
- if isRun:
- if $MeshInstance.get_Current_frame()>=45:
- isRun=false
- transform.origin=m_vPosition
- func _physics_process(delta):
- pass
Advertisement
Add Comment
Please, Sign In to add comment