Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

player leaning unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Leaning: MonoBehaviour
{
	//Input settings
    public KeyCode leanLeftKey;
	public KeyCode leanRightKey;

    //Leaning
    public Transform Normal;
	public Transform Lean_Right;
    public Transform Lean_Left;

	//Smoothing
    public float LeanSmoothing = 10;

	//private vars
	private int curAim = 0;

    // Update is called once per frame
    void Update()
    {
		AimInput();
        DetermineAim();
        DetermineLean();
    }
	//Determine aim from player
	private void AimInput()
	{
		curAim = 0;
		if(Input.GetKey(leanLeftKey)) curAim += 1;
		if(Input.GetKey(leanRightKey)) curAim -= 1;
	}

	//Move cam to position
    private void DetermineAim()
    {
        Vector3 target = Normal.position;
        if(curAim == -1)
            target = Lean_Right.position;
		else if(curAim == 1)
			target = Lean_Left.position;
		

		transform.position = Vector3.Lerp(transform.position, target, Time.deltaTime * LeanSmoothing);
    }

	//rotation cam
    private void DetermineLean()
    {
        Quaternion target = Normal.localRotation;
        if(curAim == -1)
            target = Lean_Right.localRotation;
		else if(curAim == 1)
			target = Lean_Left.localRotation;

        transform.localRotation = Quaternion.Lerp(transform.localRotation, target, Time.deltaTime * LeanSmoothing);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# how to stop user type into combobox 
Csharp :: downloading a large file asp boilerplate (abp) 
Csharp :: death transition unity 2d 
Csharp :: Handle all AggregateExceptions when using Task.Whenall() async 
Csharp :: hacking 
Csharp :: download file c# 
Csharp :: C# accesseurs 
Csharp :: linq cross join 
Csharp :: identity-1.us-south.iam.test.cloud.ibm.com:443 
Csharp :: upcasting and downcasting in c# 
Csharp :: Razor do while loop 
Csharp :: date format full month name c# selenium 
Csharp :: wcf service dependency injection 
Csharp :: windows form button image size 
Csharp :: C# verify "no other" call xunit 
Csharp :: how to set window position 
Csharp :: getcomponent rigidbody2d 
Csharp :: c# listview 
Csharp :: unity reload script assemblies 
Csharp :: c# winforms input 
Csharp :: csharp nullable types 
Csharp :: out variable in c# 
Csharp :: ik nothing is happening unity 
Csharp :: vbnet programatically convert type to db type 
Html :: html rupee symbol 
Html :: p5 cdn 
Html :: align center inner div using bootstrap 
Html :: button verlinken html 
Html :: html video autoplay IPHONE 
Html :: whatsapp message html a tag 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =