I've got a model with cars moving over the road. To make roads length similar to real-life sizes I had to change the scale so the cars turned into points (4px*2px).
Are there any facilities in AnyLogic 7 PLE to, for ex, zoom one of the cars and track it?
Yes, it is possible. If you want to zoom in one car and follow it in 3D (like if the car has GoPro at top), use Camera object with dynamic coordinates. Railway Station example model and its cameraOnTrain object illustrates the concept.
In case if you want to do similar thing in 2D space (GTA2 view mode), you may drag & drop empty Group element. In its On Draw action use the code:
getPresentation().getPanel().setOffsets( 300-agent.getX(), 300-agent.getY());
The code will constantly move frame, so car always will appear with in the bottom right corner of the 300x300 square, drawn from top left corner. Zoom can be adjusted with mouse wheel, or with code as well:
getPresentation().getPanel().setZoom( double value);
Related
how to rotate the yellow cube towards the car ? I have a spinning camera, I think this is the case
Are you trying to do with with code? I remind you StackOverflow is for programming. For other game related things there is gamedev.stackexchange.com.
If you are doing this with code - and given that I don't know how the scene tree looks like - I suggest using look_at. Something like this (code for the Camera):
look_at(car.global_transform.origin, car.global_transform.basis.y)
There car is a reference to the car. I can't tell you how to get one without looking at the scene tree, beyond that you can probably use get_node. So car.global_transform.origin is the position of the car in global coordinates. And car.global_transform.basis.y is the direction towards the up of the car.
The method look_at needs an up vector because there are infinite ways to look at a given point (rotate around the view line). Thus, we do not want an up vector that matches the view line. For example, Vector3.UP won't work if the camera is looking directly up or directly down.
And if you just want to rotate this in the designer. You can use the gizmo you see when you select it. You can drag the blue ring until it is aligned correctly.
The de facto standard for this gizmos is that x is red, y is green, and z is blue (this is true in Godot, Blender, and plenty of other software). So the blue ring rotates around the z axis. You can also find that rotation in the inspector panel, look for rotation degrees for the z under transform.
I remind you that if you place the Camera as a child node of another Spatial, it will keep its position and orientation relative to it. So placing the Camera as child of your player character (e.g. a KinematicBody) is often good enough for the early stages of development, as that guarantees that the Camera follows the player character. No coding necessary. You may want a more elaborate Camera control later, which would require some code.
Since you mention "spinning camera", perhaps you want a Camera that orbits around a point. The easier way to do this is to add an auxiliary Spatial for the point the Camera rotates around. Let us call it Pivot, and rotate that. For clarity, I'm suggesting a setup like this:
PlayerCharacter
└ Pivot
└ Camera
Here the Pivot follows the player character. And the Camera follows the Pivot. So moving the player character moves the Camera, and rotating the Pivot makes the Camera orbit. This is just lacking some code to make the Pivot rotate. For example something like this (code for Pivot):
global_transform.rotate_y(Input.get_axis("camera_left", "camera_right"))
Where "camera_left" and "camera_right" are actions configured in the Input Map (in Project settings). Which reminds me, you can set actions from code with Input.action_press, so there could be code somewhere else (e.g. _input) writing these actions from mouse movement.
Camera Control does not have to be hard.
How is it possible object can pass through ring spirte like in the image below?
Please can you help me I have no idea how can i do that.
I think you posted a incorrect image. To get the image you posted you just have to draw the red bar on top of the black ring.
I guess you want the ring on the left side to be on top and the right side to be over so it visually goes through. Well this is simply not so easy in 2D since draw order.
I have a couple of suggestion you can explore.
Always draw the ring on top of the bar but when a collision is happening you calculate where the bar overlaps and don't draw the pixels in that place. You can use a Pixmap for calculations like this. Depending on the size of your images this could be very expensive to calculate each frame.
A faster but slightly more hacky way could be to split red bar in multiple images and if a certain part of it should be overlapped by the ring draw it first otherwise draw it after the ring. Depending on what the red bar is going to look in your end product and how much possible angles the bar could have I can imagine this can be very tricky to get right.
Use 3D for this. You could have a billboard with a slight angle for the ring and have the bar locked on the distance axis at the rings center. However, on certain angles of entrance and exit you will get Z fighting since the pixels will be at the same distance from the camera. This might or might not be noticable and I have no idea how LibGDX would handle Z fighting.
I wanna add this solution :
if the object gonna pass through the ring horizontally i propose to devise sprite ring in to to sprite (sprite 1 & sprite 2)
you just have to draw sprites in that order :
Sprite1
Sprite Object
Sprite2
You can do the same if the object is gonna pass through ring vertically
PS : this solution don't work if the object is going to passs through ring both Vertically and Horizontally
Hope this was helpfull
Good luck
Let's say I have a Sprite Sheet of a character in a game. There are 4 frames of him walking to the right direction, his shape changing in each frame. How do I define the shape for each individual frame when I add a physics body to this sprite?
I'm under the impression that I have to split the sprite sheet into individual images and define the shape for each image, but if that's the case I don't know what to do from there, programming-wise.
You cannot have different physics bodies for each frame of a sprite. You can try to get it close for most of the frames. If you choose to go the separate frame route, you will have to write your own animation function to animate the sprites.
Please don't try to do that. It'll completely kill your physics simulation.
The problem with it is that the mass of a shape is calculated from its area. If you have a character animation - e.g. walking, swinging his - he would gain weight when the arms are stretched and loose weight when the arms are next to the body.
Try not to be too exact about the collision shapes - the player usually won't see the difference anyways. Just make it good enough.
One option is to approximate the shape by using a union or intersection of your animation frames.
Take a look at this tutorial - it's for cocos2d - but the physics shape creation section is basically the same for corona.
http://www.raywenderlich.com/33525/how-to-build-a-monkey-jump-game-using-cocos2d-2-x-physicseditor-texturepacker-part-1
Near the center is a more detailed explanation how to create collision shapes for animations.
I have rotary encoder with RGB LED illuminated Shaft (Bourns PEL12T-4226F-S1024) and I am designing volume knob using Solidworks 2013, that will be used with this encoder. Now, I've managed to design basic shape and made extrusions, then add a hole for potentiometer shaft, that is all ok. But, between potentiometer hole upper plate and global upper plate I need empty space, so the knob will transfer illuminated colors. How do I add empty space between two planes using Solidworks? And how do I "cut" slots from chamfered surface, so the illumination can be visible?
This is very easy to do.
Click on the Cut Extrude symbol and then click on the top face on the model and select the top view and now u can see the center of the knob hole click circle and click on that and draw the circle define it and extrude it all the way.
For a general 3D graphics application, we see from clicking at the windows, we can select an object in the scene graph, I am wondering what's the behind principal of this screen picking in 3D graphics?
Usually you will want to implement mouse picking (ray picking) like this:
take mesh(es) and its bounding volume(s)
transform mesh(es) and its bounding volume(s) to world space as usual (using its world matrix)
take mouse cursor coordinates (x, y)
unproject ("undo projection") 2D screen space mouse coordinates to 3D ray in world space using inverse view and inverse projection matrices
check for collision between ray and mesh bounding volume (coarse, fast) and/or mesh triangles (precise, slow)
if intersected, mark object as picked
repeat for all objects
if multiple objects get picked, choose nearest to camera
BTW, quick googling returns plenty of theoretic info on that topic with practical implementations using different programming languages.