Hi everyone!
Having seen how helpful the community of BlenderArtists are, i was wondering if there was anyone out there who could help port these scripts (movement, and ray shooter with bullet spawner) to the new blender 2.53 GE?!
I am having no luck:( Looking in Blender 2.49b console window still to no avail.
Bullet script:
import random
import math
# Get controllers
controller = GameLogic.getCurrentController()
# get the spawner's reference name
spawner = controller.owner
target_colider = controller.sensors["Target Colider"].owner
# Get sensors
ray = controller.sensors["ray"]
running = controller.sensors["run"].positive
fired = controller.sensors["fire"].positive
reload = controller.sensors["reload"].positive
scope = controller.sensors["scope"].positive
# Get actuators
recoil = controller.actuators["play_recoil"]
scope_in = controller.actuators["scope_in"]
#define variables
isFiring = False
ammo = getattr(controller.owner, "ammo")
clips = getattr(controller.owner, "clips")
scopeval = False
canfire = True
#define event
if scope:
if not running:
scopeval = not scopeval
canfire = not canfire
GameLogic.addActiveActuator(scope_in, scopeval)
if reload:
if clips > 0:
if ammo < 1:
setattr(controller.owner, "clips", clips - 1)
setattr(controller.owner, "ammo", 200)
if fired:
if not running:
if canfire == True:
if ammo > 0:
GameLogic.addActiveActuator(recoil, 1)
setattr(controller.owner, "ammo", ammo -1)
if ray.positive:
# Position & orient the "target collider" #
###############################################
#target_colider.worldPosition = ray.hitPosition
#target_colider.worldOrientation = spawner.worldOrientation
# Make the hit object to loose health #
###########################################
object_hit = ray.hitObject
try:
new_health = object_hit['Health'] - 9
except:
pass
else:
if new_health > 0:
object_hit['Health'] = new_health
else:
object_hit.endObject()
# Affect the object's velocity & torque #
#############################################
# Set the bullet's force applied in one frame (In newtons)
bullet_force = 200
try:
velocity_obey_prop = object_hit['Velocity_Obey']
except:
pass
else:
if velocity_obey_prop > 0:
force_x = -spawner.worldOrientation[1][0] * (1-abs(spawner.worldOrientation[2][1])) * bullet_force * velocity_obey_prop
force_y = spawner.worldOrientation[0][0] * (1-abs(spawner.worldOrientation[2][1])) * bullet_force * velocity_obey_prop
force_z = spawner.worldOrientation[2][1] * bullet_force * velocity_obey_prop
force = (force_x,force_y,force_z)
object_hit.applyForce(force, 0)
try:
torc_obey_prop = object_hit['Torc_Obey']
except:
pass
else:
if torc_obey_prop > 0:
force_x = -spawner.worldOrientation[1][0] * (1-abs(spawner.worldOrientation[2][1])) * bullet_force * velocity_obey_prop
force_y = spawner.worldOrientation[0][0] * (1-abs(spawner.worldOrientation[2][1])) * bullet_force * velocity_obey_prop
force_z = spawner.worldOrientation[2][1] * bullet_force * velocity_obey_prop
dx = ray.hitPosition[0] - object_hit.worldPosition[0]
dy = ray.hitPosition[1] - object_hit.worldPosition[1]
dz = ray.hitPosition[2] - object_hit.worldPosition[2]
tx = -(force_y * dz) + (force_z * dy)
ty = (force_x * dz) - (force_z * dx)
tz = -(force_x * dy) + (force_y * dx)
torque = (tx,ty,tz)
object_hit.applyTorque(torque, 0)