Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ramp : MonoBehaviour
- {
- // Start is called before the first frame update
- GameObject Weight;
- GameObject Ramp;
- Vector2 Velocity;
- float m = 20;
- float u = 0.15f;
- public float Fn;
- public float Fu;
- public float Fx;
- public float Fr;
- public float Fg;
- float a;
- float cosa;
- void Start()
- {
- Velocity = new Vector2(0, 0);
- Weight = GameObject.Find("Weight");
- Ramp = GameObject.Find("Ramp");
- }
- // Update is called once per frame
- void Update()
- {
- float angle = 360 - transform.localEulerAngles.z;
- Fg = m * 9.82f;
- cosa = Mathf.Cos(angle*Mathf.Deg2Rad);
- Fn = cosa * Fg; //Normalkraften Fn
- //Fu = -(u * Fn); //Friktionskraften Fu
- Fu = m * 9.82f * u;
- Fx = Mathf.Sin(angle* Mathf.Deg2Rad) * Fg; //Kraften som drar den framåt Fx
- //float Fx1 = Mathf.Abs(Fx);
- Fr = Fx - Fu; //Den resulterande kraften
- a = Fr / m; //resulterande accelerationen
- if (Input.GetKeyDown(KeyCode.UpArrow))
- {
- transform.Rotate(0, 0, -2);
- }
- if (Input.GetKeyDown(KeyCode.DownArrow))
- {
- transform.Rotate(0, 0, +2);
- }
- //Accelerationen ska beräknas enligt de krafter som påverkar vikten (tyngdkraft, normalkraft, friktionskraft)
- //O,1 unity enheter per sekund (i kvadrat)
- float ar = 0f;
- if (Fx > Fu || Velocity.x > 0)
- {
- Fr = Fx - Fu;
- ar = Fr / m;
- ar = ar * Time.deltaTime;
- }
- Weight.transform.Translate(Velocity);
- Velocity.x += ar;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement