Issue with code of animated car driving on road - p5.js

My code is supposed to use the mouse coordinates to draw a road when the mouse is clicked. Then, a car will drive continuously on it. The issue with my code is that the delay to have the car move on the road does not work properly. This piece of code:
var startTime = parseInt(new Date().getTime())
while (parseInt(new Date().getTime()) - startTime < 5000) {
print("waiting...")
}
drawCar(points[i][0],points[i][1])
is supposed to add a delay between the movements of the car so that the car movement can be visible to the user. The issue is that running the code will crash the page. I have already tried setTimeout() but this does not work properly for my needs. This function successfully adds a delay at the first time it is run but does not add a delay afterwards.
Code: https://editor.p5js.org/emanuele.saladini/sketches/SgcNhZjQS

Related

How to get a death animation for my character in ActionScript 3 (Adobe Animate)

So basically I have two questions. I am also copying off this video from 2014: https://www.youtube.com/watch?v=w8JgpEjm8i8&t=2792s
Question 1
At the end of the video above the guys computer completely crashed and he wasnt able to show the end of how to setup a death animation for my player (link). So currently I have setup a movie clip of the death animation - just the playing spinning around - and put it in another movie clip called 'All Sprites' in which I have my other movie clips such as the different walking directions. So I have placed it in there, labelled it with "Link Death Frame". I then went back to the main script and added code so that once my player dies, the animation will play. Such as:
~
if(linkHealthBarMC.scaleX <= 0.01)
{
linkAlive = false;
}
trace(linkAlive);
if(linkAlive == false)
{
linkMC.gotoAndStop("Link Death Frame");
}
~
However, the issue comes in which the animation doesnt actually play, it just goes straight to the first frame and doesnt play. I have tested it and I know for sure that it gets stuck on the first frame and that something must be wrong with the animation as I tested it with another animation and it worked fine (once I met the requirements for the animation to play). So does anyone have any idea how I can fix this issue so that my character can play a death animation?
Question 2
How do I stop time? Like just completely freeze everything after my character is dead? Because at the moment I am just going to the first frame of the death animation and can still move and attack.
I'd assume this is on an EnterFrame loop. Then you would have two possible causes for this:
1.) You're loop is constantly checking if the 'linkAlive' if statement is false (which it is) and setting your Animation to the first frame. You can check this method by putting a Trace statement in your if statement and if the output window overflows, then that's your culprit.
2.) What you want is gotoAndPlay(-insert label here-)
Tho it is outside the scope of the question you have, I create a variable~Switch State machine to control states for me:
1.) Current State as a number (int, number, or uint)
2.) function with a switch statement (Switch is kind of a fancy if Statement)
3.) inside the cases are instructions
switch(current_state){
case 1:
linkMC.gotoAndPlay('death animation');
break;
}
if (current_state != 1){
-put movement code here-
}
This is close to what I use for my game. Just checking states or you can have a variable like the one above that explicitly checks for the death state and remove the ability to move. If you use a mouse (and I assume event listener) then you can remove the event listener for the mouse. If you use a solution like keyboard inputs then an if statement would be more what you are looking for.

Playing same animation action on loop without reseting position

I am trying to run a walking animation on a gltf model from animationClip. The goal is to play the walking animation whenever the up arrow key is pressed and keep it running if the key is held down. For that i am playing the animation whenever first animation is completed but the animtion only plays once. It triggers the finished event but there is no animation.
walkAction = mixer.clipAction(walkClip);
walkAction.loop = THREE.LoopOnce;
walkAction.enabled = true;
walkAction.paused = true;
walkAction.clampWhenFinished = true;
walkAction.play();
mixer.addEventListener('finished', restoreAnim);
function restoreAnim(event){
mixer.removeEventListener('finished', restoreAnim);
walkAction.play();
}
The above code was to keep the character keep moving but it clamps up after the first time but the finished eventListener is still triggered repeatedly.
Also is there any other way to do this. I am using walking animation from mixamo and the problem persists even when using multiple animations and changing different properties.
Where you are downloading that animation. if it's a site like "mixamo.com" there will be an option called "In place". you have to check that check box before you download your selected animation. Then your animation will play without repositioning its place.
check this "In place" checkbox

Second client's canvas not registering input? Unity

Obligatory "i'm very new". I couldn't figure out how to hook up a canvas that the player interacts with (chooses which team they'll be playing on in the game) that I had would work out if it was in the scene that the player prefab would be spawned into. So I put the canvas into the prefab with the player and set it as inactive once they select which team.
It works flawlessly for the host client (changes their "playerTeam" int and spawns them where they should be spawned) but when the second client joins their canvas is there, but won't take any input. I know it's this because the debug.log i put in right after input is not being run. here are the code segments that are necessary.
i have the canvas disabled by default and activated after an (isLocalPlayer) run on a script on the parent object. I can't add a networkID to the canvas because the prefab parent object has the networkID and they both can't have one, which means I cannot use (isLocalPlayer) on the canvas script, which may be the issue. But I also can't have the canvas on the actual level screen because even if i find the game object of the canvas, i don't know how to make it find which player to assign the playerTeam int to.
The following is run on a script attached to the canvas (of which the empty player object is the parent of)
Button CT = chooseCT.GetComponent<Button>();
CT.onClick.AddListener(parent.GetComponent<Sync>().CmdpickedCT);
and this is the code that runs on a script on the parent object
[Command]
public void CmdpickedCT()
{
GetComponent<Movement>().playerTeam = 2;
teamSelector.SetActive(false);
}
I apologize if I'm missing something big here. Thanks for any help.
for more information i have more stuff in the movement script run once the playerTeam is set to something other than 0, this also works on the host. Any other information you can give about how to pass info from the objects in the game scene to the instantiated objects would be great too. Thanks again.
Additional information, it seems like if i have both the second client and first client on the canvas at the same time, I cannot choose my team with either. It says "Trying to send command for object without authority".

GUI simulation only shows end result

I've got a Simulation built and need to add a GUI onto it to choose x amounts of steps to simulate. The program right now only shows me the end result and I need it to show the simulation.
I can see in the command window its running, but just wont show movement of characters.
The simulation is a 2d grid of a room and people moving around based on who they are next and how happy they would be. Without the GUI the program works fine so I assumed if putting the code from the main arg in the non GUI code into the action performed for my simulate button it would work.
Right now this is the actionPerformed method:
private void simButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Simulator simulator = new Simulator(50, 50, 43);
// simulate the project for 10 rounds
simulator.simulate(10);
// simulator.setVisible(true);
}

Unity2D Set Time Trial That Kills Player When Over

I can't find any answers to this. What I want is to set a 5 min time limit that begins when the level begins and ends when level ends. I also want it to kill the player if it runs out. This is for Unity2D and I want the timer to be seen at top left or right of screen. So basically I need a time limit like that of Super Mario. In C# code please.
Break up your problem into easier tasks. You will need some type of timer, and you will want to know how to 'kill' the player.
To create a timer, you can take advantage of how Update runs once per frame. Unity also comes with a Time class. In Time, there is a variable deltaTime which keeps track of the time in seconds to complete the last frame. Some other things you might want to add on to your class that acts as a timer is when to start and stop the timer.
To output the value from a timer to the game, you might want to use Unity's UI system and canvas. You might create a text object that is part of a canvas and anchor that text object to the top left corner.
To 'kill' a player, you can have some method that runs once the timer reaches the time in question and run the kill logic you want.
Helpful links:
MonoBehavior Update: https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html
Time: https://docs.unity3d.com/ScriptReference/Time.html
UI: https://unity3d.com/learn/tutorials/topics/user-interface-ui
You can create a class that keeps track of the timer and to check if the requirements to fail are still there.
In this case you can have a float for the timer, and a bool for the condition whenever you completed the level or not.
It the timer reaches zero, check if the bool is still false, if it is, then you call something like KillPlayer(). If you complete the level by hitting a trigger or anything that will know if the level should be considered finished, you set the bool to true.
So your final check could look like this:
public float levelTimer = 300f;
public bool levelComplete = false;
void Start()
{
levelTimer = 300f;
levelComplete = false;
}
void Update()
{
levelTimer -= Time.deltaTime;
if(levelTimer <= 0 && !levelComplete)
{
KillPlayer();
//Something like a Game Over screen maybe
}
}
I hope this help you in the right direction.

Resources