Ross3 – What’s going on?

Posted by B on Thursday Sep 15, 2011 Under Game Development, Ross Cubed

So here is where I am with Ross3:

The camera (demo) is working properly (I think), the avatar controls are coming together (using a character controller – not too hard here), though the jump needs some SERIOUS tweaking, and the basic mechanics are seeming to work. So what do I have yet to do so I can get a playable demo to you? Well, wow… I guess I’l start the list:

1) GUI – the actual interface to give you info about what’s going on. There are still a few things that are in the game play (or not…) that will inform the HUD GUI design. I am going to mock one up after I get this posted to give you an idea of what I am thinking.

2) RigidBody motors – This is for all NPC’s. This will allow them to move about, but still have collisions. Also, this is because I have been having trouble getting two CharControllers to interact properly with one another – which seems to be a common problem (Unity support?).

3) RigidBody drag – this is so Ross can pull boxes as well as push them. I figure this will be necessary when you push the box against a wall and need it somewhere else.

4) Music – this is going to be a task. I want the music to be dynamic and responsive to what is happening in the game. BUT I don’t want to script every little thing. I will if I have to, but I would rather like it to be autonomous, with me doing set up and the scene controlling the music. I would like to use it to add to the feel of the game, like they do in movies. I know that I could use triggers, and I probably will make use of a fair amount of them, but I also want all the music and sound in a level to flow seamlessly together, which means beat matching and timing issues. I have a grand idea (think Peter and the Wolf) and it is going to be a lot of work to accomplish it. I will keep you posted.

5) Spawning – I don’t want the player to have to restart the level when he dies, since I want it to be a casual game that is easy to pick up and put down. SO I’m thinking a spawn system that uses checkpoints. We’ll see how well it works out. I haven’t looked into this yet, but I expect that it will be harder than I think.

6) Point Systems – Yeah. People expect points. ‘Nuff said.

7) Millions of tiny things I haven’t yet foreseen – Really. There is probably more that I haven’t thought of than I have.

Tags : | Comments Off

Below you will find the playable camera demo. Move with the arrow keys or WASD, jump with SPACE, but there isn’t anything to do, this is just to see how the camera works.

Tags : | Comments Off

I am working on the camera control for Ross3 and it’s going pretty well. So well, in fact, that I think it is almost there. Of course it will have to be tested in play and adjustments made, but the base is there… I think.

The Goal

Make a camera script that will follow the player position and rotation, while maintaining a visual. In essence, I don’t want a wall or ceiling to block the view of the player.

The Plan

Steal other people’s hard work. And then, before you get all huffy-puffy, alter it to suit my needs.

The Implementation

I decided to start with the SmoothFollowWithCameraBumper script from the unitycommunity wiki page – written (I think – there is no name on the .js file) by Daniel P. Rossi, so thanks go to him.

This was a great start, but as I ran around a test level I found that I needed more. I decided that more Raycasting was needed (isn’t this just typical?). After playing around a bit I am casting a ray from the target to the default position of the camera. If the ray hits anything that isn’t the camera, the camera height is set to hit.point.y (the height of the point hit by the ray) minus a bumper hight offset (in this case 1). I didn’t want to change the x and z of the position of the camera, just the height.

Great. This works, but now if something is behind the player and lowering the camera by interfering with the raycast, we often can’t see the player. Solution? Raycast backward from the target, like the original Rossi file did. I am raycasting as far as the “distance” variable and if I hit something I adjust the x,y and z positions of the camera. If I don’t hit something then I just set the y position as above.

I also found an issue with standing in front of a bad guy. While I admit that this won’t happen much, it will (most likely) be possible to do and I don’t want the camera bouncing around as the bad guy turns and his corners interfere with the ray for a few frames. To solve this I started using the Physics.Raycast() overload with a LayerMask. If you look at the code you will see that there is one in there and in the editor this is exposed as a list from which you can select. I’m not sure if I am going to have the camera ray ignore the bad guys or not, but I can with a few clicks of the mouse, should I desire to do so.

That’s pretty much the gist of it. Below is the actual code, with a few comments in it. You may notice two lines setting the targetLookOffset commented out, this is because I’m not sure if I am going to move it around or not. Play testing…

The Outcome

Play a small demo to see how it works.

The Code

var target : Transform;
var layerMask : LayerMask; // which layers to interact whith while checking for things between the cam and target
var distance : float = 7.0;
var height : float = 4.0;
var damping : float = 5.0;
var smoothRotation : boolean = true;
var rotationDamping : float = 10.0;
var sideOffset : float = 0.0; // used to position the camera to the left or right of the target
							  // similar to an over the shoulder view of a third person shooter
// set the following public if you need to access them or want them visible in the editor
private var targetLookAtOffset : Vector3;     // allows offsetting of camera lookAt, very useful for low bumper heights
private var bumperDistanceCheck : float = 2.5;  // length of bumper ray
private var bumperCameraHeight : float = 1.0;   // adjust camera height while bumping
private var bumperRayOffset : Vector3;    // allows offset of the bumper ray from target origin

function Awake() {
	target = GameObject.FindWithTag("Player").transform;
	targetLookAtOffset.x = sideOffset;
	// comment the next line out if you want to specify the length of the bumper ray manually
	bumperDistanceCheck = distance;
}

function setTarget(newTarget : Transform) {
	target = newTarget;
}

function FixedUpdate() {
    var checkForCamDirection =  target.TransformPoint(sideOffset, height, -distance) - target.position;
    var wantedPosition = target.TransformPoint(sideOffset, height, -distance);
    var back = target.transform.TransformDirection(-1 * Vector3.forward);
    // check to see if there is anything between the target and the camera
    var hit : RaycastHit;
  	Debug.DrawRay(target.position, checkForCamDirection, Color.green);
    if(Physics.Raycast(target.position, checkForCamDirection, hit, distance, layerMask) && hit.transform != this.transform){
		if (Physics.Raycast(target.TransformPoint(bumperRayOffset), back, hit, bumperDistanceCheck, layerMask)) {
	    // clamp wanted position to hit position
	        wantedPosition.x = hit.point.x;
	        wantedPosition.z = hit.point.z;
	        wantedPosition.y = Mathf.Lerp(hit.point.y + bumperCameraHeight, wantedPosition.y, Time.deltaTime * damping);
	       // targetLookAtOffset = Vector3(0,0,2);
	    }
	    else{
    	 	wantedPosition.y = Mathf.Max(target.position.y, hit.point.y - bumperCameraHeight);
    	 	//targetLookAtOffset = Vector3.zero;
   		}
    }
    targetLookAtOffset = Vector3(0,0,2);

    transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * damping);

    var lookPosition : Vector3 = target.TransformPoint(targetLookAtOffset);

    if (smoothRotation) {
        var wantedRotation : Quaternion = Quaternion.LookRotation(lookPosition - transform.position, target.up);
        transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
    }
    else {
        transform.rotation = Quaternion.LookRotation(lookPosition - transform.position, target.up);
    }
}
Tags : | Comments Off

Going Live

Posted by B on Tuesday Sep 6, 2011 Under General Comments

Welcome to BillyGoat! I keep hearing that I need to be on LinkedIn and all the social sites to do networking, but I decided that having nothing to show to interested parties is equally as depressing and counterproductive as having no interested parties.

So to get this party started I present – Me! This page is my ever evolving portfolio and development blog. My goals are simple: 1) to allow you to play, critique and (hopefully) enjoy games and projects that I am working on and 2) to get a sense of who I am and how I go about things. The dev blog will be where you find the stuff to make the second goal achievable.

So, for now, there isn’t much that is up here and there is less that is playable. I am working on a few things to get the Ross3 demo up and running, but I will go into that in a separate post. Thanks for checking it out and come back often.

Tags : | Comments Off