Jump to content

  • Log In with Google      Sign In   
  • Create Account


Neoshaman

Member Since 12 Aug 2003
Offline Last Active Jun 29 2013 10:38 AM
-----

Topics I've Started

Collision for tangential movement in unity

16 June 2013 - 01:51 PM

I wonder what you guy would do for a cheap replacement of character controller in unity.

I'm trying to make a game with megadrive's sonic pinball physics, think (technically) about mario galaxy meet tony hawk with sonic's high speed. Currently I use a simple raytracing, but I'm looking to listen collision around the sphere collider.

In my case i tried:

  1. Rigidbody turn the game in a slide show, Intel atom n455 for the win (actually I like the limitation so it can run on most machine).
  2. Kinetic body don't collide with scenery (don't listen collision).
  3. Character controller don't rotate.
  4. Sweeptest() and SweepTestAll() but walls and inward curve fails dramatically. + it does not work with the flash preview of unity 3.x

I want to be able to move the character according to tangent of arbitrary complex volumes. For example, taking slope change higher than 90° and leave the case handling with special case code (for example stopping at a wall or falling down a cliff)

Currently my code is this one, with sweeptest(): http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.SweepTest.html

 

private void UpdateSurfacePosition()
{
Ray//origine, direction
ground_check_ray = new Ray( gameObject.transform.position, -gameObject.transform.up);// * (Momentum.magnitude + 1));
RaycastHit
raycast_result;
Rigidbody
rigid_body = gameObject.rigidbody;


rigid_body.detectCollisions = false;
rigid_body.isKinematic = true;



bool onGround;// =
//Physics.Raycast( ground_check_ray, out raycast_result );//ray, hit
//rigid_body.SweepTest(-gameObject.transform.up, out raycast_result);//direction, hit, distance

raycast_result = new RaycastHit();
RaycastHit[] contacts = rigid_body.SweepTestAll(-gameObject.transform.up);

rigid_body.SweepTest(-gameObject.transform.up, out raycast_result);


if (contacts.Length > 0)
{
onGround = true;
int i=0; while (i != contacts.Length)
{
raycast_result.normal += contacts[i].normal;
i++;
}
raycast_result.normal = raycast_result.normal.normalized;
}
else
{
onGround = false;
}


debug1 = "Normal > " + raycast_result.normal.ToString()
+ " Position > "+ raycast_result.point.ToString()
//+" transform > "+ raycast_result.transform.name.ToString()
+ " Contact > " + contacts.Length
;


if ( onGround )
{
Vector3
next_position;

//UpdateOrientation( gameObject.transform.forward, raycast_result.normal );

UpdateMoveOrientation( gameObject.transform.forward, raycast_result.normal );
next_position = GetNextPosition( raycast_result.point );
rigid_body.MovePosition( next_position );


//ground_direction = raycast_result.normal;
}
else//onAir
{
//if forward close to dot.Y = abs(1) choose -up if 1 and up if -1
UpdateMoveOrientation( gameObject.transform.forward, raycast_result.normal );
}
}

 


[SOLVED] Relative cam movement and momentum on arbitrary surface

06 April 2013 - 12:32 AM

Hello!

 

I have been working on a game for quite long, think sonic classic physics in 3D or tony hawk psx, with unity3D. However I'm stuck at the most fundamental aspect of movement.

 

The requirement is that I need to move the character in mario 64 fashion (or sonic adventure) aka relative cam input:

1. the camera's forward direction always point input forward the screen, left or right input point toward left or right of the screen.

2. when input are resting, the camera direction is independent from the character direction and the camera can orbit the character

3. when input are pressed the character rotate itself until his direction align with the direction the input is pointing at.

 

It's super easy to do as long your movement are parallel to the global horizontal (or any world axis). However when you try to do this on arbitrary surface (think moving along complex curved surface) with the character sticking to the surface normal (basically moving on wall and ceiling freely), it seems harder. What I want is to achieve the same finesse of movement than in mario but on arbitrary angled surfaces. There is more problem (jumping and transitioning back to the real world alignment and then back on a surface while keeping momentum) but so far I didn't even take off the basics.

 

So far I have accomplish moving along the curved surface and the relative cam input, but for some reason direction fail all the time (point number 3, the character align slowly to the input direction).

 

Do you have an idea how to achieve that?

 

Here is the code and some demo so far:

 

the camera code

using UnityEngine;
using System.Collections;

public class CameraDrive : MonoBehaviour
{
    public GameObject
        targetObject;
    
    public Transform
        camPivot,
        camTarget,
        camRoot,
        
        relcamdirDebug;
        
    float
        rot = 0;
//----------------------------------------------------------------------------------------------------------
    void Start()
    {
        this.transform.position = targetObject.transform.position;
        this.transform.rotation = targetObject.transform.rotation;
    }
    
    void FixedUpdate()
    {        
    //the pivot system
        camRoot.position    = targetObject.transform.position;
        
    //input on pivot orientation
        rot = 0;
        float mouse_x        = Input.GetAxisRaw( "camera_analog_X" );                //
        rot                 = rot + ( 0.1f * Time.deltaTime * mouse_x );            //
        wrapAngle( rot );                                                            //
        
    //when the target object rotate, it rotate too, this should not happen

                
        UpdateOrientation(this.transform.forward,targetObject.transform.up);

        camRoot.transform.RotateAround(camRoot.transform.up,rot);
        
    //debug the relcam dir
            RelativeCamDirection()
            ;
        
    //this camera
        this.transform.position    = camPivot.position;                            //set the camera to the pivot
        this.transform.LookAt( camTarget.position );                            //
    }
//----------------------------------------------------------------------------------------------------------
    public float wrapAngle ( float Degree )
    {
        while (Degree < 0.0f)
        {
            Degree = Degree + 360.0f;
        }
        while (Degree >= 360.0f)
        {
            Degree = Degree - 360.0f;
        }
        return Degree;
    }
    
    private void UpdateOrientation( Vector3 forward_vector, Vector3 ground_normal )
    {
        Vector3
            projected_forward_to_normal_surface = forward_vector - ( Vector3.Dot( forward_vector, ground_normal ) ) * ground_normal;
        
        camRoot.transform.rotation = Quaternion.LookRotation( projected_forward_to_normal_surface, ground_normal );
    }
    
    float GetOffsetAngle( float targetAngle, float DestAngle )
    {
            return ((targetAngle - DestAngle + 180)% 360)  - 180;
    }
//----------------------------------------------------------------------------------------------------------
    void OnDrawGizmos()
    {
        Gizmos.DrawCube(
            camPivot.transform.position,
        new Vector3(1,1,1)
            );
        
        Gizmos.DrawCube(
            camTarget.transform.position,
        new Vector3(1,5,1)
            );
        
        Gizmos.DrawCube(
            camRoot.transform.position,
        new Vector3(1,1,1)
            );
    }
    
    void OnGUI()
    {
        GUI.Label(new Rect(0,80,1000,20*10), "targetObject.transform.up : " + targetObject.transform.up.ToString());
        GUI.Label(new Rect(0,100,1000,20*10), "target euler : " + targetObject.transform.eulerAngles.y.ToString());
        GUI.Label(new Rect(0,100,1000,20*10), "rot : " + rot.ToString());

    }
//----------------------------------------------------------------------------------------------------------
    void RelativeCamDirection()
    {
                
        float
            input_vertical_movement     = Input.GetAxisRaw( "Vertical" ),
            input_horizontal_movement     = Input.GetAxisRaw( "Horizontal" );
        
        Vector3
            relative_forward     = Vector3.forward,
            relative_right         = Vector3.right,
            
            relative_direction    =
                ( relative_forward    * input_vertical_movement )
                +
                ( relative_right    * input_horizontal_movement )
                ;
        
        MovementController MC = targetObject.GetComponent<MovementController>();
        
        MC.motion = relative_direction.normalized * MC.acceleration * Time.fixedDeltaTime;
        
        MC.motion = this.transform.TransformDirection( MC.motion );
        
        //MC.transform.Rotate(Vector3.up, input_horizontal_movement * 10f * Time.fixedDeltaTime);    
    }
}


 

 

The movement code

 

using UnityEngine;
using System.Collections;

public class MovementController : MonoBehaviour
{
    public float
        deadZoneValue = 0.1f,
        angle,
        acceleration  = 50.0f;
    public Vector3
        motion ;

//--------------------------------------------------------------------------------------------    
    void OnGUI()
    {
        GUILayout.Label( "transform.rotation : " + transform.rotation );
        GUILayout.Label( "transform.position : " + transform.position );
        GUILayout.Label( "angle : " + angle );
    }
    
    void FixedUpdate ()
    {
        
        Ray
            ground_check_ray = new Ray( gameObject.transform.position, -gameObject.transform.up );
        RaycastHit
            raycast_result;
        Rigidbody
            rigid_body = gameObject.rigidbody;
        
        if ( Physics.Raycast( ground_check_ray, out raycast_result ) )
        {
            Vector3
                next_position;
            
            //UpdateOrientation( gameObject.transform.forward, raycast_result.normal );
            UpdateOrientation( gameObject.transform.forward, raycast_result.normal );    
            next_position = GetNextPosition( raycast_result.point );
            rigid_body.MovePosition( next_position );
        }
    }
//--------------------------------------------------------------------------------------------    
    
    
    private void UpdateOrientation( Vector3 forward_vector, Vector3 ground_normal )
    {
        Vector3
            projected_forward_to_normal_surface = forward_vector - ( Vector3.Dot( forward_vector, ground_normal ) ) * ground_normal;
        
        transform.rotation = Quaternion.LookRotation( projected_forward_to_normal_surface, ground_normal );
    }
    
    private Vector3 GetNextPosition( Vector3 current_ground_position )
    {
        Vector3
            next_position;

//        //--------------------------------------------------------------------
//        angle = 0;
//        Vector3 dir = this.transform.InverseTransformDirection(motion);
//        angle = Vector3.Angle(Vector3.forward, dir);// * 1f * Time.fixedDeltaTime;
//        
//        if(angle > 0) this.transform.Rotate(0,angle,0);
//        //--------------------------------------------------------------------
        
        
        next_position =
            current_ground_position +
            gameObject.transform.up * 0.5f
                + motion
                ;
        
        return next_position;
    }
    
}


 

Demo:

 

https://dl.dropbox.com/u/24530447/flash%20build/litesonicengine/LiteSonicEngine5.html


Binary DM - final take

08 April 2010 - 09:10 AM

It's been six year, in this thread i had started thinking about how to make a binary dm, following path set by member like Sunandshadow, Bishop_pass, Kordova and Oluseyi. After some extensive research and try, i think i'm close to that dream and i want to share it with you. Here the first part of the DNA of game and story: There is a lot to explain, but basically this is the structure and function that create the experience of a story in a goal structure. I need to explain the details and nuance of the different functions. The model is highly relative, to use it you need to take a point of view, it's also scalable and fractal, it can explain a single action to whole overall story movement from the same work. There is a concept of "space", the story can exist simultaneously in physics, psychologic, social and morals space at the same time, and those space communicate by sharing function between them. Other part of the model is a dynamic chart that plot emotion movement and how they relate to this one. And there is also a methodologies to handle dynamics in a plot and made it practical for implementation.

edge grabbing in 3D platformer

15 January 2009 - 11:39 PM

Hello everybody! I have recently learn to use BLITZ3D and it's amazing how efficient and fast it is to make 3D game with, it's even easier than making 2D game as it handle anything fundamental like animation, camera and collision with breeze! That's how i have start to code a 3D plateformer in the like of Mario 64. So far so good, after 2 weeks of work i have even done more thant previously plan without prior knowledge in 3D game making. Now i start to increase my ambition, from a "showcase" prototype i want to do a fully playable game but still educational for me. My goal is to implement nearly all the mario move in the game. The game woud be a pure and simple platformer, only platform and the character and collectible. But the things i didn't expect is that i have no idea how to do "grab edge" efficiently in 3D. I mean without tagging the level prior to the play, i want it systemic so the player can thrust his ability and not read the designer's thought. Anyone have an idea, did this idea was discuss before in another topic? EDIT: After thinking a little more about my post, i think i need to precise the problem more! What i want is "viable edge detection for grabbing onto an arbitrary mesh in runtime" :) of course the viability of edge is decide by parameter to tweak

Storytelling in video games through analysis of the ren ai genre

10 April 2007 - 02:40 AM

Hello While working on the project Love Revolution, i did a little analysis of storytelling in game and how they relate with the narratives. The analysis cover the adventure genre, the visual novel and dating sim like gameplay and narration, but it apply for other genre as well as they share grounding mecanism. I will be glad to share comments and point of view about it, and have your opinions and sentiments. Thanks! analysis

PARTNERS