Surreal: Slasher-RPG

Story:
No story.

***Objective:
Your objective; survive.

***Details:
Extremely realistic survival game. No mini-map, no health bar, no cross-hairs.

***Controls:
W - Forward
A - Left
S - Backward
D - Right
Space - Jump
Ctrl - Crouch

***Scripts:

Movement:


import bge
from bge import logic

cont = logic.getCurrentController()
obj = cont.owner

xVelocity = yVelocity = zVelocity = 0

if logic.keyboard.events[bge.events.AKEY] == 2:
    xVelocity = -6
        
if logic.keyboard.events[bge.events.DKEY] == 2:
    xVelocity = 6

if logic.keyboard.events[bge.events.WKEY] == 2:
    yVelocity = 6
        
if logic.keyboard.events[bge.events.SKEY] == 2:
    yVelocity = -6
    
if logic.keyboard.events[bge.events.SPACEKEY] == 2:
    zVelocity = 10
    
if xVelocity != 0 and yVelocity != 0:
    xVelocity *= 0.7
    yVelocity *= 0.7

if obj.rayCast( [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z - 1.1], obj, 0.0) != (None, None, None):
    obj.setLinearVelocity([xVelocity, yVelocity, zVelocity], 1)

Mouse:


import bge
from bge import logic
from bge import render

cont = logic.getCurrentController()
object = logic.getCurrentScene().objects
camera = object["Camera"]
empty = object["Empty"]
camOri = camera.orientation

mouse = cont.sensors["Mouse"]
width = render.getWindowWidth()
height = render.getWindowHeight()
pos = mouse.position
xPos = int(width/2) - pos[0]
yPos = int(height/2) - pos[1]

if yPos < 0 and camOri[2][1] < 1 and camOri[2][2] >= 0.8:
    yPos = 0
elif yPos > 0 and camOri[2][1] < 1 and camOri[2][2] <= -0.8:
    yPos = 0

camera.applyRotation([yPos*0.0005, 0.0, 0.0], 1)
empty.applyRotation([0.0, 0.0, xPos*0.0005], 1)

render.setMousePosition(int(width/2), int(height/2))

Let us be begun

Even though I guess/am sure that this would mostly belong into the Discussion Forum (ironically), all you have to do is to make an Else after each If Instance, commanding either xVelocity=0 or yVelocity=0. You also can make another If Instance that includes both Left- and Right-Movement and one If Instance including both Forth- and Back-Movement, and then make an Else Instance for each of them. (That MIGHT end up better to control, even if it looks a Bit unclean.)


cont = bge.logic.getCurrentController()
obj = cont.owner


collision = cont.sensors["Collision"]


keyboard = bge.logic.keyboard
ACTIVE = bge.logic.KX_INPUT_ACTIVE


xVelocity = 0
yVelocity = 0
speed = 5


if keyboard.events[bge.events.AKEY] == ACTIVE:
    xVelocity = -speed
if keyboard.events[bge.events.DKEY] == ACTIVE:
    xVelocity = speed
if keyboard.events[bge.events.WKEY] == ACTIVE:
    yVelocity = speed
if keyboard.events[bge.events.SKEY] == ACTIVE:
    yVelocity = -speed
if xVelocity == 0:
    obj.setLinearVelocity([0, yVelocity, 0], 1)
if yVelocity == 0:
    obj.setLinearVelocity([xVelocity, 0, 0], 1)
if xVelocity != 0:
    obj.setLinearVelocity([xVelocity, 0, 0], 1)
if yVelocity != 0:
    obj.setLinearVelocity([0, yVelocity, 0], 1)
if xVelocity != 0 and yVelocity != 0:
    obj.setLinearVelocity([xVelocity*0.707, yVelocity*0.707, 0], 1)
if keyboard.events[bge.events.SPACEKEY] == ACTIVE:
    obj.setLinearVelocity([xVelocity, yVelocity, speed], 1)

This works. All you need is a collision sensor and movement is done.

Here is the “mouseLook” script. However, I would like a creative way to cap his up and down rotation of camera. For instance, I don’t want him to be able to look at his back :stuck_out_tongue:


import bge
from bge import logic
from bge import events
from bge import render


cont = logic.getCurrentController()
object = logic.getCurrentScene().objects
camera = object["Camera"]
cube = object["Cube"]


mouse = cont.sensors["Mouse"]
width = render.getWindowWidth()
height = render.getWindowHeight()
pos = mouse.position
xPos = int(width/2) - pos[0]
yPos = int(height/2) - pos[1]


camera.applyRotation([yPos*0.001, 0.0, 0.0], 1)
cube.applyRotation([0.0, 0.0, xPos*0.001], 1)


if not mouse.positive:
    xPos = 0
    yPos = 0


if pos != [int(width/2), int(height/2)]:
    render.setMousePosition(int(width/2), int(height/2))
else:
    xPos = 0.0
    yPos = 0.0

Here’s a work-in-progress of the main character.


He’s only 458 faces so far. Next step is to add details, ears, and hands.

Crits&Comments are welcome!

Some progress on adding details to the main character. He’s now 540 faces.


Main character almost finished. Unfortunately the hands put on another 500 faces to his total face count. But considering they are the most important part and the part you (in first person) will see the most. I decided to add as much detail as possible (including ears!). Making his total face count 1084 faces.


Please CRIT&COMMENT!

H Y P E R R E A L

After having finished rigging my mesh… I noticed a problem I am not capable to fix. Notice how the knee bends the wrong way? How do I use Inverse Kinematics to have it so that it bends the other way? (The way it’s suppose to bend) :stuck_out_tongue:


First, make the leg already bent when modeling. That way the IK knows the way it should bend. Second, you can set the limits and stiffness for bending of bones (don’t know where it is these days, I’m sure you’ll find it though if you look on the properties tab when selecting bones in pose mode).

The character looks good, but as I say, try to model him in a contracted pose, with arms legs and spine already slightly bent the way they normaly bend. Also better th model the hands as slightly grasping.

@Smoking_mirror: Thank you for the feedback! I’ve made the corresponding adjustments and now the rig works fine!

Next I’m trying to make ultra-realistic movement. Has anyone worked extensively on this?

u could do some “artificial mocap” video ur self doing walks, jumps, etc or what not, even from first person (strap a camera to ur head) and then load it up to blender and move the armature to where u r in the vid :stuck_out_tongue:

This is definitely how to get ultra-high realism. However, I meant more as in… When he starts to walk he doesn’t just go from 0 m/s -> 2 m/s instantaneously. He gradually reaches he’s normal walking speed as we humans do. Same for running. Notice how in most blender games you seem to just float in the air and gradually descend when you jump? I don’t want that. I don’t know what units blender uses for it’s base units. Or what the mass is in. But I want a realistic movement system. (It will be in First Person, the rigged mesh I made won’t be used for the main player. I only did that in case I needed for something).

Can you use python?

If so the best way to get ultra realism in character movement is to use the speed of the character (collected by using python) to drive the speed of the animations.

for example:

adding_amount = character_speed

max_frame = 30

if animation_frame < max_frame:
           animation_frame += adding_amount
else:
           animation_frame = 1

That way if you are moving slowly then the animation will play slowly, but when you move quickly, it will play quickly. You will also need a stride length bone which the feet handles (the bones which the leg IK targets) can be parented too. Scaling this bone makes the stride length longer or shorter. When your speed is high you take long strides, but if you are only turning around, you just shuffle your feet in place.

Here’s an example of this method:

The down side of this method is that it’s difficult to mix with other animations (such as falling or raising a gun, as you can’t blend animations which are driver by properties). This might have been changed in the most recent versions of blender, but I don’t think so.

The other way of doing it is to have a walk, fast walk, run and sprint animation and mix them depending on the speed of the character. That’s the method I finally chose, as although it’s less acutrate it does have more flexibility.

So I’ve revamped this project… I’m currently working on the main environment and how to move around the environment.

Consider the following environment I have:


I want to add as much realism to the game while staying as optimized as possible.

  1. What is the best Day & Night system?
    (with at least a Sun, Moon, clouds, stars)
  1. What is the best terrain generation system? (with at least trees, grass, vegetation, hills, valleys, water streams)

Ok. So here’s the new skybox:


I’m using a shader someone else developed and I really have no idea how it works, however, it’s fantastic.