Devblog
Pushing a car into the ocean

Pushing a car into the ocean

It has been a while since the last posting! No worries, things are still happening.

This update is mostly about scripting the game using Adventure Creator add-on for Unity. I have chosen a simple scenario for this post: manipulating a rigid body in order to drive a car off of a ship.

Adventure Creator is quite awesome. It provides a framework for easy gameplay scripting inside Unity. It makes nearly anything possible straight out of the box and also handles save files, which is a great help for an indie developer.

The framework is geared towards creating adventure games, but it can as easily be extended to function as a back-bone for any type of game really.

A screen capture of Adventure Creator’s Game Editor -panel

Coming up!

I will follow up this post with another, more advanced action list: figuring out what side of a door your character is on.

We will start with the simpler one: pushing a car into the ocean using rigid body forces. This setup does not require any custom Adventure Creator code, but it requires a simple controller script that is triggered by Adventure Creator’s actions.

Hotspot Settings

Before any actions can be run, we need to add an element that will activate the action list. In this case that element will be a hotspot: the old car on the deck of the ship.

Inventory Interaction
Dust Particle Systems
Hotspot Trigger
Interactive Boundary
Walk to Marker
Object to Highlight
Remember…
Nav Mesh Obstacle

Tooltips

Hover on top of the ℹ icons to see more information

Action List

Adventure Creator’s scripting is done via action lists. These are simple files or game objects with a list of actions that will be performed in order of execution.

Adventure creator has a ton of pre-made actions and creating custom actions is very straightforward and the scripting documentation is top notch!

You can add if clauses, like checking if you have an inventory item, and branch on different paths in the action list. The system basically is visual scripting, but with more user-friendly terms.

For hotspots in the level, the actions lists can exist within the level hierarchy, but for prefabs, the lists need to be separate asset files. For this car scene, the action list is in the level as a game object.

Camera Switch
Play Speech

For controlling this car puzzle, we need only one action list that controls the whole cutscene. The cutscene is not in its final form right now- even the car is a wrong model! I just put in something to be able to test the flow.

  1. Play Speech (Player): Let’s see..
  2. Call Event: DummyCarController.ReleaseRigidBody
  3. Camera Switch: OldCarFollowCamera
  4. Play Speech (Player): Hey!
  5. Wait: 1s
  6. MoveToPoint (Player, walk): OldCar_fallpoint
  7. Wait: 1s
  8. MoveToPoint (Player, run): OldCar_fallpoint
  9. MoveToPoint (NPC, run): OldCar_fallpoint
  10. Play Speech (NPC): Stop!
  11. Wait: 3s
  12. CallEvent: DummyCarController.SetForce
  13. Wait: 4s
  14. Camera Switch: Reset
  15. CallEvent: DummyCarController.LockRigidBody
  16. Play Speech (Player): Oh god!
  17. Play Speech (NPC): It was the captain’s car!

With all of these actions running in sequence, this is what it looks like:

A screen capture of the Adventure Creator Action list in the game build

Custom Scripting

This first example is almost exclusively done with built in Adventure Creator actions. The only place where we require some additional code is when the car rigid body is activated. For this I used a simple C# component added to the car.

The component makes sure that the car wheels spin and that we can release and lock the car physics. The car starts out locked, and is released on command. I also lock the car after it is submerged in the waves to that it does not keep on falling forever!

The car controller
DummyCarController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DummyCarController : MonoBehaviour
{
    private float _steeringAngle;

    public Rigidbody _rigidBody;

    public WheelCollider ColliderFR, ColliderFL;
    public WheelCollider ColliderBR, ColliderBL;

    public Transform WheelFR, WheelFL;
    public Transform WheelBR, WheelBL;

    public float _force;

    private void UpdateWheelPoses()
    {
        UpdateWheelPose(ColliderFR, WheelFR);
        UpdateWheelPose(ColliderFL, WheelFL);
        UpdateWheelPose(ColliderBR, WheelBR);
        UpdateWheelPose(ColliderBL, WheelBL);
    }

    private void UpdateWheelPose(WheelCollider _collider, Transform _transform)
    {
        Vector3 _pos = _transform.position;
        Quaternion _quat = _transform.rotation;

        _collider.GetWorldPose(out _pos, out _quat);

        _transform.position = _pos;
        _transform.rotation = _quat;
    }

    public void ReleaseRigidBody()
    {
        _rigidBody.isKinematic = false;
    }

    public void LockRigidBody()
    {
        _rigidBody.isKinematic = true;
    }

    private void FixedUpdate()
    {
        UpdateWheelPoses();
        _rigidBody.AddForce(Vector3.forward * _force * Time.deltaTime);
    }

    public void SetForce()
    {
        //_force = 0f;
    }
}

As the game is in very early stages, everything is a bit of a work in progress. At this time all of my cars are the same car model and all of my characters looks identical. Even all the text is a placeholder. I am still at a stage where I am just hacking together functionality and ideas. I try not to make anything too polished yet. With these tests I can better figure out what I need to create. For example, for this scene, I need a cloth from under which the car slips out, I need a destructible ship wall, I need destructible props on the ship deck that the car can crash into, I need a cool effect for when the car hits the water surface and I need dialogue for the 2 characters when they observe the Car falling over the rail.

Leave a Reply

Your email address will not be published. Required fields are marked *