I can't make my dinosaur jump in Scratch. How do I fix it? - mit-scratch

I've recently made a game in Scratch named Dino T-rex. However, I can't make the dinosaur jump when an obstacle comes. It doesn't jump when the up arrow is clicked. Rather, it just goes front. How do I fix it?

When you use the glide command your dino is only moving to the right and then stopping because the second glide block is to the same coordinates. You only want to change the second coordinate because then, the Y coordinate, so that the dino doesn't move left nor right, just up then straight down.
Also, you should not make it wait for 2 seconds, it is far too long. It is better if you just have a blank wait block so it goes straight up then back down.

In the block you are showing for the UP arrow, you are moving the sprite to coordinates -147,26 and then, after 2 seconds you are moving it again to -147,26. So there is no movement there (other than the first glide which moves the dino to the right).
You have to move the dino up (by changing the glide's Y-coordinate final destination) to a higher point, but you have almost the same value (y: 26 units) that you have when the dino appears in the starting position (y: 27 units)
The dino is moving to the right because you are only changing the x coordinate (x is the horizontal coordinate)
I think that you simply mixed X's and Y's

You are first starting the dino at x=-175 and y=26, then you are gliding to x=-147 and y=26, then you are gliding to x=-147 and y=26.
Your first mistake is that you are gliding along the x-axis instead of the y-axis because y-axis is going up and down.
Your second mistake is that you are making it glide back to the same spot.

Related

How do you make an object in Scratch have horizontal momentum when you release dragging it?

I'm trying to implement this in Physica, my Scratch-based physics engine. I tried adding it and the ball glitched out (couldn't move on the x axis at all). Does anyone know how to do this?
If it's a physics engine, then every object should have added variables for speed, and then you manipulate the speed:
To change the speed:
When ... (whenever your drag release is)
set Vx to 10
this example has a drag function:
https://en.scratch-wiki.info/wiki/Draggable_Sprite_Feature
In the physics engine, speed constantly moves your object:
When green flag
forever
add Vx to x
add Vy to y
#boisvert pretty much answered your question. But if you want to sense drag releasing, use this code:
when green flag
set drag mode to draggable
forever
wait until touching mouse pointer and mouse down
wait until not mouse down
point toward mouse pointer
set V to distance to mouse pointer * 2
along with this:
when green flag
forever
set V to V*0.9
move V steps
if on edge, bounce
It's not the most perfect code, but it will work
Example: https://scratch.mit.edu/projects/558479500/

Explanation of how to calculate transforms in Unity

I am getting started with Unity and am just trying to get my head around the units. What are these units? It seems they are their own 'quantity' and to treat 2 units as 2 times the value of 1 unit.
Anyway - I am trying to workout how to optimally calculate transforms to objects sit exactly where I want them to.
In my scene I have a terrain and a cylinder as so:
As you can see my cylinder is floating. I want the cylinder to sit perfectly on top of the terrain.
My terrain is at the following transform: 0,0,0 and scale 0,0,0 (not sure how to tell it's dimensions yet).
My cylinder is part of a new object, as so:
My FirstPersonPlayer is at transform: 85.9,2.165,51.8 and scale 1,1,1. My Cylinder is at 'localposition' 0,0,0 and local scale 1.2,1.8,1.2
Now - the transform of FirstPersonPlayer on the y axis appears to be what I need to correct.
Currently it is set to 2.165 and is floating a bit above the terrain.
Through manually shifting it, around 1.85 looks about right - but I want to know how to calculate that, rather than doing a finger in the air 'that looks about right'.
Can anyone help me? (Before you suggest using gravity etc , I actually am, but don't want the player falling as soon as they start, however slight that may look or feel.
Many thanks,
As per #Nikola Dimitroff the answer is:
You don't have to compute anything, hold Shift + Control and drag the object. Every game engine ever made calls this "Snap to Ground"
I appreciate and agree with the other comments.

How can I rotate and move a cylindrical rod from one side with respect to other side in unity?

I have 3 questions here. If answer of 2nd question is yes, then i dont need answer for 1st question.
I want to rotate one end of this rod and when i rotate 2nd end. i want it to move parallel to 1st end. Right now when i rotate right end in upper direction, left end goes in lower direction and pivot remains at its position. When rod is in straight line, one end will simply rotate and when rod is already tilted, it will move one end in line with the other end.
Can i simple move one end of rod? instead of rotating it just simply move one end of rod upwards and not the entire rod?
when i use gravity on the ball it falls on the rod and take the rod down with it. if i make rod kinemetic, it wont move or rotate. i want ball to use gravity but not to drag rod with itself.
Okay: if I understand it correctly, you want to move one end of the rod up, while the other is remaining where it is, like a tennis bat?
To move only one end of the rod, while the other one remains where it is, I would suggest using a parent object.
Have a parent object (Parent_Rod), make the rod the child of the aforementioned parent.
Now, set up up, so the root of the Child_Rod, that you do not want to move is at the Parent_Rods root. So the non-using end of your rod should be at [0, 0, 0,] of the parent. Then don't rotate the rod object itself, but the parent of it. This way, the rotation will be around the transform of the parent, where one end of your rod is.
Regarding the force from collision: You should not use gravity on your rod and make the rigidbody kinematic. That way you can easily control the rotation of the parent via script, while the rod itself remains unaffected of collisions.
Hope this helps, hope I got the question correctly.

SpriteKit move node with physics rather than updating position

My main character moves by touching and holding him and then moving your finger left or right to move the character. To do this I just simply update the node's x position (walks left and right on a flat surface) in touchesMoved() with the x position of the touch location, and apply an animation depending on the direction he's moving.
I want to kind of take this to the next level and accomplish the same effect, but using physics, so that when I'm done moving him and release my finger, he may slide a little bit in the direction he was moving given the speed I was moving him at, if that makes sense. Does anyone know how I can accomplish this effect?
Would I have to do as I'm currently doing and update the position as it moves, but also apply a force/impulse at the same time? Kind of confused on how to approach this
Moving the physics body via force, impulse, or velocity will automatically update the player position.
So you will have to play around with the correct way to accomplish your goal. But based on this, what I would suggest is replace your .position code with .physicsBody!.velocity code in your touchesMoved. Then, on your touchesEnded, you can apply a bit of an impulse to give the player that little bit of an "on ice" effect to keep them going a tad.
You will need to experiment with how much velocity you want to get the character to move at the correct speed, and then you will need to play with the impulse figures as well to get it just right.
This could get a bit tricky though, in touchesMoved... because at some point you will want to reset the velocity to 0 (so they stop moving when your finger stops).
To do that, you will need to to use the .previousLocation from your touch object, and compare the distance of X moved. if the distance X moved is >0 (or some deadzone threshold) then apply the velocity; if the deltaX is 0, then set the velocity to 0.
This may actually be more complicated than just using .position to move the character, then having the character slide a bit with physics on touchesEnded.
You will have to play with it to get it right.

How to get a ball/sphere to stop

I got a field in unity3d that has some depressions in it (like small holes). The field's slope always leads towards the nearest depression.
A sphere is dropped at random somewhere in the field, rolls around a bit until it stops in one of the depressions.
The problem is, this is taking too long. It could roll around for 5-10 seconds until it stops. I'd like to stop faster.
Any ideas how I can achieve this?
Edit: The main issue is when the ball is next to the depression, but it has speed that is 90 degrees from the hole, then it starts going in circles and takes a while to stop.
Ok, after getting some advice in the comments, and experimenting, this is the way I solved it:
Apply a small measure of strength towards the depression
If the current velocity is more than 30 degrees away from the center of the depression, slow the ball (apply strength in the opposite direction of the velocity)
IF the ball gets very near the center of the depression, stop it and place it in the center
Thanks for all the tips. If anyone comes up with a better way, I'm still open to suggestions.