Unity VideoPlayer: Missing Rewind-Method - unity3d

The idea is to take an 360-degree Video and map it to the sky box using the "Unity Interactive 360 Video Sample" from the asset store scene. The Camera moved through a mall at recording time.
We want the video's spectator to be able to "walk forwards", to "walk backwards", "to stand still" in the mall in VR in Unity at running time.
To do so we want to use the oculus joystick to move the player through the video. That is, scrolling the current video clip time forwards and backwards at runtime using the value from Input.GetAxis("Vertical").
Does work: Moving forwards works like a charm.
Does not work: Moving backwards does not work because playback speed cannot be negative.
This is the current script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class OculusInput_VideoControl : MonoBehaviour {
VideoPlayer videoPlayer = null;
// Use this for initialization
void Start () {
videoPlayer = (VideoPlayer)FindObjectOfType(typeof(VideoPlayer));
}
// Update is called once per frame
void Update () {
float joystickPosition_from_minusone_to_one = Input.GetAxis("Vertical");
videoPlayer.playbackSpeed = joystickPosition_from_minusone_to_one;
OVRDebugConsole.print(videoPlayer.playbackSpeed + " ### " + joystickPosition_from_minusone_to_one );
}
}
These are the systems specs:
How do we embed walking backwards?
if (joystickPosition_from_minusone_to_one < 0) videoPlayer.time -= (int) Mathf.Abs(joystickPosition_from_minusone_to_one);
is laggy!
if (joystickPosition_from_minusone_to_one < 0) videoPlayer.frame -= (int) Mathf.Abs(joystickPosition_from_minusone_to_one * 10);
is laggy too!

Negative playback speed is platform dependant.
If it is laggy, then this could be because of your platform.
You can and should however multiply the value you want to substract with Time.deltaTime.
It will probably improve your lag issue, but might not fix it completely.
Also, why Cast your Mathf.Abs to int? Is there a special reason for it?
Casting to int will round your float, which may be undesired behaviour.
Try the following code
if (joystickPosition_from_minusone_to_one < 0)
{
videoPlayer.time -= Mathf.Abs(joystickPosition_from_minusone_to_one) * Time.deltaTime;
}

Related

I ask for code ideas, the reason why I write below

Hello everyone. I have a character like the picture below, I want when playing the game, this character collides with another character, this character will be hidden (Exactly hide the entire skin shirt, okay? , but the character still moves normally) after about 10 seconds, it will show the skin again as shown below.
I'm stuck in the code. I tried to enable skinnedmeshrenderer , but it forces the sence to reload and it doesn't work very well. If you have any ideas, please let me know. Thank you!!!!
So for this you need to look up how to use colliders. You might want a simple box collider, or even a mesh collider. Then you need to tag the colliders (Go to Learn.Unity or the YouTube website to look for some guides if you don't know about these).
Then use private void OnCollisionEnter(Collision col){} and check col.tag to see if it's what you want and set the character GameObject to innactive* character.SetActive(false);
Then, set a float timer to 10 timer=10; and in Update run
if (timer > 0)
{
timer -= Time.deltaTime;
if (timer <= 0)
{
character.SetActive(true);
}
}
which will reactivate your character after 10 seconds.
* Note
If you don't want to turn the gameObject off, you can instead save the mesh in a variable then set it to null for 10 seconds before restoring it
Alternate solution:
Script used:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField] SkinnedMeshRenderer skinnedMeshRenderer;
Mesh mesh;
float timer = 0;
// Start is called before the first frame update
void Start()
{
mesh = skinnedMeshRenderer.sharedMesh;
}
// Update is called once per frame
void Update()
{
if (timer > 0)
{
timer -= Time.deltaTime;
if (timer <= 0)
{
skinnedMeshRenderer.sharedMesh = mesh;
}
}
if (Input.GetMouseButtonDown(0))
{
skinnedMeshRenderer.sharedMesh = null;
timer = 10;
}
}
}
Model "Steve" thanks to Penny DeBylle

Unity 2D rhythm game prefab object spawn slower after build

im totally newbie in unity, my brother helped me in coding and now we stuck on a problem. we're making a 2D mobile (android) rhythm game based on our folk songs. the problem is like in the title.
game demo: https://youtu.be/UJl461f8QZc
its just miliseconds late but its so uncomfortable, we only adjust the time just like the songs original beats per minute.
this is the code we write to define the time so we can write the time (ms) in the editor
/* void Update()
{
transform.Translate(0 , -speed * Time.deltaTime , 0);
timer += Time.deltaTime;
}*/
private void FixedUpdate()
{
rb.velocity = -transform.up * speed * 45f * Time.fixedDeltaTime;
timer += Time.deltaTime;
}
as you can see, the fixedDeltaTime doesn't work either
and this is the code to spawn the tiles :
public void Muncul()
{
int RG = Random.Range(0 , graphics.Length);
int SD = Random.Range(0 , spawner.Count);
GameObject t = Instantiate(tiles , spawner[SD].position , spawner[SD].rotation);
t.GetComponent<SpriteRenderer>().sprite = graphics[RG];
}
and to create how many tiles to spawn, we use code to record the song we played and then it detects the beats in song to spawn the tile per beat.
i appreciate any help, and sorry for my bad english

Why does exporting to Unity WebGL change the speed of objects in my game?

GOAL
So I have a space-invaders type game I have made to practise unity and I want to upload it to Itch.io as I have done in the past.
This is a clip of the game.
I switched platforms to WebGL in Build Settings etc, and everything worked fine in Unity.
PROBLEM
However when I built it and uploaded the zip file to Itch.io, the aliens are now a lot faster than usual. (Be aware there may be other things that have changed, I just haven't been able to get to them since it is extremely hard).
CODE
Alien movement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AleenController : MonoBehaviour
{
Rigidbody2D rigidbody;
public float speed = 10f;
ScoreController scoreController;
AudioSource aleenDie;
void Start()
{
scoreController = GameObject.Find("Canvas/Score").GetComponent<ScoreController>();
rigidbody = GetComponent<Rigidbody2D>();
aleenDie = GameObject.Find("Main Camera/AleenDie").GetComponent<AudioSource>();
}
void Update()
{
rigidbody.MovePosition(transform.position + new Vector3 (0, -1, 0) * speed * Time.deltaTime);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "laser")
{
aleenDie.Play();
scoreController.score += 1;
Destroy(gameObject);
}
}
}
NOTE
I am really struggling to find out what is wrong here, since everything is fine in unity. If you do need more details just leave a comment.
If you use physics you should
not set or get values via Transform at all
do things in FixedUpdate
In general though in your case instead of using
void Update()
{
rigidbody.MovePosition(transform.position + new Vector3 (0, -1, 0) * speed * Time.deltaTime);
}
at all simply set the velocity once like e.g.
void Start ()
{
...
rigidbody.velocity = Vector3.down * speed;
}
The rest seems to depend a bit on your screen size. Looks like you are moving your elements in pixel space -> the smaller the display the less pixel distance between the top and bottom -> the faster elements seem to travel.

How to make wall push the player in unity3d?

How to make wall push the player ?
i had tried to use transform.translate, however i found out directly manipulating transform
component of an object ignores physic, and someone suggest me to use force instead.
however, when i use force, the wall
just stop when it hit my player, as if my player can't be moved.
Below are my code.
using UnityEngine;
using System.Collections;
public class left : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
rigidbody.AddForce (-40 * Time.deltaTime, 0, 0);
if (transform.position.x < -14) {
transform.position = new Vector3(15,15,908);
}
}
}
Increase the mass of the wall or reduce the mass if the player
First of all, you should put a collider on both the box and the player. Then create a script on the player. Something that would tell it that when the box collided with the player, it would move to the destined position, depending on the force applied.
something like
OncollideO(){
player.transform.position.x -= Time.deltaTime * 1;
}
you do not have to set the vectors manually to be able to move them.
you may also use left, right, up, and down in moving gameobjects.
might as well as tell you to research about LERP which may be able to help you in coding it.

visual lag of the moving picture in Unity3D. How to make it smoother?

I make a game in Unity3D (+2D ToolKit) for iOS.
It is 2d runner/platformer with side view. So on screen is moving background and obstacles. And we control up/down the main character to overcome obstacles.
The problem is that the moving picture has a visual lag. In other words, it moves jerkily or creates the tail area of the previous frames on iOS-devices. In XCode the number of frames is 30 and over.
I have objects 'plain' with the following script:
public class Move: Monobehavior
{
private float x;
public float Speed = 128.0f;
void Start()
{
x = transform.position.x;
}
void Update()
{
x += Time.DeltaTime *Speed;
Vector3 N = transform.position;
N.x = mathf.FloorInt(x);
transform.position = N;
}
}
The question is how to make the move of background smoother, without jerks and flicker on screen while playing? Maybe the problem is in framerate parameter.
Can anybody help me to find a solution?
I'd say it's the use of the FloorInt function which will move the background only in steps of 1 which is rather not smooth. It should get better when you comment that line out. Do you have any special reason why you are doing the FloorInt there?
The use of floor will definitely hurt your performance. Not only is it one more thing to calculate, but it is actually removing fidelity by removing decimals. This will definalty make the movement look 'jerky'. Also, update is not always called on the same time inteval, depending on what else is happening during that frame, so using Time.delaTime is highly recommended. Another thing, you do not need to set variables for x and Vector3 N, when you can update the transoms position like the code below. And if you have to, you sill only need to create one variable to update, and set your position to it. The code below just updates the players x position at a given rate, based on the amount of time that has passes since the last update. There should be no 'jerky' movement. (Unless you have a serious framerate drop);
public class Move: Monobehavior
{
public float Speed = 128.0f;
void Update()
{
transform.position =
(transform.position.x + (speed*Time.DeltaTime),
transform.position.y,
transform.position.z);
}
}